Text blinking jQuery

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

    This is the EASIEST way (and with the least coding):

    setInterval(function() {
        $( ".blink" ).fadeToggle();
    }, 500);
    

    Fiddle

    Now, if you are looking for something more sophisticated...

    //Blink settings
    var blink = {
        obj: $(".blink"),
        timeout: 15000,
        speed: 1000
    };
    
    //Start function
    blink.fn = setInterval(function () {
        blink.obj.fadeToggle(blink.speed);
    }, blink.speed + 1);
    
    //Ends blinking, after 'blink.timeout' millisecons
    setTimeout(function () {
        clearInterval(blink.fn);
        //Ensure that the element is always visible
        blink.obj.fadeIn(blink.speed);
        blink = null;
    }, blink.timeout);
    

    Fiddle

提交回复
热议问题