Text blinking jQuery

后端 未结 30 1675
我寻月下人不归
我寻月下人不归 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:59

    Blinking !

    var counter = 5; // Blinking the link 5 times
    var $help = $('div.help');
    var blinkHelp = function() {
        ($help.is(':visible') ? $help.fadeOut(250) : $help.fadeIn(250));    
        counter--;
        if (counter >= 0) setTimeout(blinkHelp, 500);
    };
    blinkHelp();
    
    0 讨论(0)
  • 2020-11-27 03:59

    Indeed a plugin for a simple blink effect is overkill. So after experimenting with various solutions, I have choosen between one line of javascript and a CSS class that controls exactly how I want to blink the elements (in my case for the blink to work I only need to change the background to transparent, so that the text is still visible):

    JS:

    $(document).ready(function () {
            setInterval(function () { $(".blink").toggleClass("no-bg"); }, 1000);
        });
    

    CSS:

    span.no-bg {
        background-color: transparent;
    }
    

    Full example at this js fiddle.

    0 讨论(0)
  • 2020-11-27 04:01

    Some of these answers are quite complicated, this is a bit easier:

    $.fn.blink = function(time) {
        var time = typeof time == 'undefined' ? 200 : time;
        this.hide(0).delay(time).show(0);
    }
    
    $('#msg').blink();
    
    0 讨论(0)
  • 2020-11-27 04:02

    I have written a simple jquery extension for text blink whilst specifying number of times it should blink the text, Hope it helps others.

    //add Blink function to jquery 
    jQuery.fn.extend({
        Blink: function (i) {
            var c = i; if (i===-1 || c-- > 0) $(this).fadeTo("slow", 0.1, function () { $(this).fadeTo("slow", 1, function () { $(this).Blink(c);  }); });
        }
    });
    //Use it like this
    $(".mytext").Blink(2); //Where 2 denotes number of time it should blink.
    //For continuous blink use -1 
    $(".mytext").Blink(-1);
    
    0 讨论(0)
  • 2020-11-27 04:04

    You can try the jQuery UI Pulsate effect:

    http://docs.jquery.com/UI/Effects/Pulsate

    0 讨论(0)
  • 2020-11-27 04:06

    This code might help to this topic. Simple, yet useful.

    <script type="text/javascript" src="http://code.jquery.com/jquery-1.4.1.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){
            setInterval("$('#myID/.myClass').toggle();",500);
        });
    </script>
    
    0 讨论(0)
提交回复
热议问题