开发者

Fade body away with simple javascript?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜