JavaScript运动

xiaoxiao2025-08-30  6

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>图片淡出</title> <style> img{ display: block; width: 230px; height: 380px; filter: alpha(opacity:30); opacity: 0.3; } h3,img{ margin:0 auto; text-align: center; } </style> <script> window.onload=function(){ var oImg=document.getElementById("img1"); timer=null; var alpha=30; function startMove(iTarget){ clearInterval(timer); timer=setInterval(function(){ var iSpeed=0; if (alpha<=iTarget) { iSpeed=1; }else{ iSpeed=-1; } if (alpha==iTarget) { clearInterval(timer); }else{ alpha+=iSpeed; oImg.style.opacity=alpha/100; oImg.style.filter=alpha+'(opacity:'+alpha+')' } },30); } oImg.onmouseover=function(){ startMove(100); } oImg.onmouseout=function(){ startMove(30); } } </script> </head> <body> <h3>图片动画淡出</h3> <img src="timg.jpg" alt="" id="img1" /> </body> </html>

鼠标滑过之前如下图:

 

鼠标划过图片,图片慢慢显示清晰,鼠标离开又回到初始状态,鼠标划上图片效果如下图:

 

转载请注明原文地址: https://www.6miu.com/read-5035447.html

最新回复(0)