Home  >  Article  >  Web Front-end  >  How to Make Text Blink with jQuery?

How to Make Text Blink with jQuery?

DDD
DDDOriginal
2024-11-01 15:51:31996browse

How to Make Text Blink with jQuery?

Making Text Blink with jQuery

To make text blink in jQuery, a JavaScript library for manipulating HTML elements, use the following steps:

<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>

This code uses the setInterval() method to repeatedly toggle the visibility of the element with the class "blink" every 500 milliseconds. When the visibility is "hidden," the text will disappear, and when it's "visible," the text will be displayed.

To stop the blinking effect, clear the interval using clearInterval() and the interval ID that was returned when setInterval() was called.

The above is the detailed content of How to Make Text Blink with jQuery?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn