Home > database >  Add a slow fadein effect to my popup modal
Add a slow fadein effect to my popup modal

Time:05-03

Can someone show me how to do a slow fadein effect to my current popup modal which opens up on click event?

here is my code

var THRESHOLD = 5 * 1000;
var lastActive = Date.now();
$(window).on('click', function() {
    if (Date.now() > lastActive   THRESHOLD) {
     $('#modal').css('display','block');
    }
    lastActive = Date.now();
});

Thanks alot

CodePudding user response:

There is a default fadeIn()/fadeOut() function in jQuery you can use, there you can pass value in milliseconds which is speed of fading-in/out your content

var THRESHOLD = 5 * 1000;
    var lastActive = Date.now();
    $(window).on('click', function() {
        if (Date.now() > lastActive   THRESHOLD) {
         $('#modal').fadeIn( 500 );
        }
        lastActive = Date.now();
    });

  • Related