Implement border flashing in Javascript

Source: Internet
Author: User

Implement border flashing in Javascript
In a new project recently, the product manager finds that when the user balance is insufficient, the product manager prohibits the user from selecting and inputting buttons, you should focus your attention on the prompt content so that you can quickly recharge your account based on the prompt content. So a few studies finally decided to make the frame of the prompt box flash to achieve the purpose of reminder. Because the project needs to be compatible with ie6, js has become the first choice. Considering that js is a single-threaded Execution Language, recursive timeout call is the first choice. First, a div with ID = blink is required, and then two classes with different color borders are named border1 and border2 respectively. The css code is as follows: 1 # blink {width: 300px; height: 36px; background-color: # ccc;} 2. border1 {border: 5px solid #000;} 3. border2 {border: 5px solid # cc0000;} And then JavaScript code: copy the code (function () {var div =$ ("# blink"); var borderFlag = false; var time; setTimeout (blinkBorder, 2000); function blinkBorder () {time = 0; for (var I = 0; I <6; I ++) {time + = 100; setTimeout (function () {modifyBorder () ;}, time) ;}settimeout (blinkBorder, 200 0);} function modifyBorder () {borderFlag =! BorderFlag; if (borderFlag) {div. removeClass ("border1 "). addClass ("border2");} else {div. removeClass ("border2 "). addClass ("border1") ;}}) () copies the entire JavaScript code segment in an immediate execution function. By setting the border transform identifier and initial time value, use the time-out call function to implement the flashing effect of the border through recursive methods. The interval call time is set to 2 seconds, And the for loop times represent the number of flashes of the border within 2 seconds. The code is very simple. If you need to test it, don't forget to introduce the Jquery library. Tags: javascript border flashing effect

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.