淡出DOM元素
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了淡出DOM元素相关的知识,希望对你有一定的参考价值。
Smoothness of fade out animation needs work
/** * Set the opacity CSS for required element */ function setOpacity(elem,level) { //if filters then IE //use alpha opacity if (elem.filters) { elem.style.filter = 'alpha(opacity=' + level + ')'; } else { //else use W3C opacity CSS elem.style.opacity = level / 100; } } /** * Fade out the required element over time using CSS */ function fadeOut(elem) { //20 frame animation for ( var i = 0; i < 100; i += 5 ) { //anonymous closure makes sure correct i is used //for each iteration (function(){ //opacity is i var opacity = i; //animation setTimeout(function(){ // Set the new opacity of the element setOpacity( elem, 100 - opacity ); //completely hide the element at 95% if ( opacity == 95 ) elem.style.display = 'none'; //for smooth animation change the timeout delay //proportionately with opacity }, ( i + 1 ) * 10 ); })(); } } //get id of element that closes element var myElm = document.getElementById('myElement'); //close the element on click myElm.onclick = function() { fadeOut(document.getElementById('fadeOutElement')); };
以上是关于淡出DOM元素的主要内容,如果未能解决你的问题,请参考以下文章
jquery 对象的 heightinnerHeightouterHeight 的区别以及DOM 元素的 clientHeightoffsetHeightscrollHeightoffset(代码片段