Text blinking jQuery

后端 未结 30 1671
我寻月下人不归
我寻月下人不归 2020-11-27 03:23

What is an easy way to make text blinking in jQuery and a way to stop it? Must work for IE, FF and Chrome. Thanks

相关标签:
30条回答
  • 2020-11-27 03:42

    I feel the following is of greater clarity and customization than other answers.

        var element_to_blink=$('#id_of_element_to_blink');
        var min_opacity=0.2;
        var max_opacity=1.0;
        var blink_duration=2000;
        var blink_quantity=10;
        var current_blink_number=0;
    
        while(current_blink_number<blink_quantity){
            element_to_blink.animate({opacity:min_opacity},(blink_duration/2),"linear");
            element_to_blink.animate({opacity:max_opacity},(blink_duration/2),"linear");
            current_blink_number+=1;
            }
    
    0 讨论(0)
  • 2020-11-27 03:44

    This is what ended up working best for me. I used jQuery fadeTo because this is on WordPress, which already links jQuery in. Otherwise, I probably would have opted for something with pure JavaScript before adding another http request for a plugin.

    $(document).ready(function() {
        // One "blink" takes 1.5s
        setInterval(function(){
            // Immediately fade to opacity: 0 in 0ms
            $(".cursor").fadeTo( 0, 0);
            // Wait .75sec then fade to opacity: 1 in 0ms
            setTimeout(function(){
                $(".cursor").fadeTo( 0, 1);
            }, 750);
        }, 1500);
    });
    
    0 讨论(0)
  • 2020-11-27 03:45

    Try using this blink plugin

    For Example

    $('.blink').blink(); // default is 500ms blink interval.
    //$('.blink').blink(100); // causes a 100ms blink interval.
    

    It is also a very simple plugin, and you could probably extend it to stop the animation and start it on demand.

    0 讨论(0)
  • 2020-11-27 03:46

    Seeing the number of views on this question, and the lack of answers that cover both blinking and stopping it, here goes: try jQuery.blinker out (demo).

    HTML:

    <p>Hello there!</p>
    

    JavaScript:

    var p = $("p");
    
    p.blinker();
    
    p.bind({
        // pause blinking on mouseenter
        mouseenter: function(){
            $(this).data("blinker").pause();
        },
        // resume blinking on mouseleave
        mouseleave: function(){
            $(this).data("blinker").blinkagain();
        }
    });
    
    0 讨论(0)
  • 2020-11-27 03:47

    here's blinking with animation:

    $(".blink").animate({opacity:0},200,"linear",function(){
      $(this).animate({opacity:1},200);
    });
    

    just give a blink class whatever u want to blink:

    <div class="someclass blink">some text</div>
    

    all regards to DannyZB on #jquery

    features:

    • doesn't need any plugins (but JQuery itself)
    • does the thing
    0 讨论(0)
  • 2020-11-27 03:48

    Here you can find a jQuery blink plugin with its quick demo.

    Basic blinking (unlimited blinking, blink period ~1 sec):

    $('selector').blink();
    

    On a more advanced usage, you can override any of the settings:

    $('selector').blink({
        maxBlinks: 60, 
        blinkPeriod: 1000,   // in milliseconds
        onBlink: function(){}, 
        onMaxBlinks: function(){}
    });
    

    There you can specify the max number of blinks as well as have access to a couple of callbacks: onBlink and onMaxBlinks that are pretty self explanatory.

    Works in IE 7 & 8, Chrome, Firefox, Safari and probably in IE 6 and Opera (although haven't tested on them).

    (In full disclosure: I'm am the creator of this previous one. We had the legitimate need to use it at work [I know we all like to say this :-)] for an alarm within a system and I thought of sharing only for use on a legitimate need ;-)).

    Here is another list of jQuery blink plugins.

    0 讨论(0)
提交回复
热议问题