jQuery “blinking highlight” effect on div?

后端 未结 15 1074
囚心锁ツ
囚心锁ツ 2020-12-04 09:24

I\'m looking for a way to do the following.

I add a

to a page, and an ajax callback returns some value. The
is fill
15条回答
  •  伪装坚强ぢ
    2020-12-04 10:12

    If you are not already using the Jquery UI library and you want to mimic the effect what you can do is very simple

    $('#blinkElement').fadeIn(100).fadeOut(100).fadeIn(100).fadeOut(100);
    

    you can also play around with the numbers to get a faster or slower one to fit your design better.

    This can also be a global jquery function so you can use the same effect across the site. Also note that if you put this code in a for loop you can have 1 milion pulses so therefore you are not restricted to the default 6 or how much the default is.

    EDIT: Adding this as a global jQuery function

    $.fn.Blink = function (interval = 100, iterate = 1) {
        for (i = 1; i <= iterate; i++)
            $(this).fadeOut(interval).fadeIn(interval);
    }
    

    Blink any element easily from your site using the following

    $('#myElement').Blink(); // Will Blink once
    
    $('#myElement').Blink(500); // Will Blink once, but slowly
    
    $('#myElement').Blink(100, 50); // Will Blink 50 times once
    

提交回复
热议问题