练习:javascript淡入淡出半透明效果
划过无透明

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>淡入淡出半透明效果</title> <style> img {width:400px;height:200px;opacity: 0.3;filter:alpha(opacity=30)} </style> </head> <body> <img src="images/4.jpg" alt="" id="img"> <script> // opacity IE8及以下版本不支持 var oImg= document.getElementById('img'); oImg.onmouseover=function(){ animate(30,100) } oImg.onmouseout=function(){ animate(100,30) } var timer = null; function animate(speed,dest){ //speed初始透明度,dest透明度目标值 clearInterval(timer); timer = setInterval(function(){ speed<dest?speed+=10:speed-=10; if(speed==dest){ clearInterval(timer); timer=null; }else { oImg.style.opacity=speed/100; oImg.style.filter="alpha(opacity:"+speed+")"; } },20) } </script> </body> </html>
    本博客主要记录自己的学习点滴~,文章来源于总结,还有在工作中实际碰到的问题以记录。
 
                    
                     
                    
                 
                    
                
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号