js多物体运动之淡入淡出效果
Posted 人在钱途
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了js多物体运动之淡入淡出效果相关的知识,希望对你有一定的参考价值。
<!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta http-equiv="X-UA-Compatible" content="ie=edge" /> <title>Document</title> </head> <style> div{width:200px;height: 200px;margin: 20px;float: left; background-color: red;filter:alpha(opacity:30);opacity: 0.3;} </style> <body> <div></div> <div></div> <div></div> <div></div> </body> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript"> window.onload=function(){ var oDiv=document.getElementsByTagName(\'div\'); for(var i=0;i<oDiv.length;i++){ oDiv[i].alpha=30; oDiv[i].onmouseover=function(){ startMove(this,100); }; oDiv[i].onmouseout=function(){ startMove(this,30); }; } }; function startMove(obj,iTarget){ clearInterval(obj.timer); obj.timer=setInterval(function(){ var speed=(iTarget-obj.alpha)/6; speed=speed>0?Math.ceil(speed):Math.floor(speed); if(obj.alpha==iTarget){ clearInterval(obj.timer); }else{ obj.alpha+=speed; obj.style.filter=\'alpha(opacity:\'+obj.alpha+\')\'; obj.style.opacity=obj.alpha/100; } },30); } </script> </html>
以上是关于js多物体运动之淡入淡出效果的主要内容,如果未能解决你的问题,请参考以下文章