开发者

Fade body away with simple javascript?

开发者 https://www.devze.com 2023-03-16 00:18 出处:网络
I want to make a simple function to fade out the body onclick. Can it be done with javascript? I can use jquery if the开发者_如何学JAVAre is no other choice.Ok so the function you need to utilize is s

I want to make a simple function to fade out the body onclick. Can it be done with javascript? I can use jquery if the开发者_如何学JAVAre is no other choice.


Ok so the function you need to utilize is setInterval inorder to acheive a "fade-out" animation.

function fadeout ( element, duration ){
   element.style.opacity = element.style.opacity || 1;
   var inter = setInterval(function(inter){
       if( element.style.opacity <= 0 ){
           clearInterval(inter);
           block.style.display = "none";
       } else {
           element.style.opacity -= (1/(duration/13));
       }
    },13); 
}

check it in action on jsfiddle


You could write the function from scratch, but jQuery's fadeOut would certainly be easier.

0

精彩评论

暂无评论...
验证码 换一张
取 消