Home > Article > Web Front-end > How can I make text elements blink using jQuery?
It's a common requirement to make text elements blink in a webpage. jQuery provides a powerful and cross-browser compatible solution for this task.
To make text blink in jQuery, we can utilize its setInterval() and css() methods. Here's a concise and straightforward code snippet:
<code class="javascript">$('.blink').each(function() { var elem = $(this); setInterval(function() { if (elem.css('visibility') == 'hidden') { elem.css('visibility', 'visible'); } else { elem.css('visibility', 'hidden'); } }, 500); });</code>
In this code, we:
The provided code works seamlessly across modern browsers, including Internet Explorer, Firefox, and Chrome.
To stop the text blinking, simply call clearInterval() on the interval ID returned by setInterval(). Here's how:
<code class="javascript">var intervalId = setInterval(function() { // Code to make text blink... }, 500); // To stop blinking, call clearInterval() like this: clearInterval(intervalId);</code>
The above is the detailed content of How can I make text elements blink using jQuery?. For more information, please follow other related articles on the PHP Chinese website!