<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style>
.shop{
width: 200px;
height:200px;
position: absolute;
left: 200px;
top: 200px;
position: relative;
background-color: red;
filter:alpha(opacity:100);
opacity:1;
}
div{
width: 200px;
height:200px;
background-color: red;
margin: 10px;
filter:alpha(opacity:100);
opacity:1;
}
</style>
<script>
window.onload=function(){
var odiv=document.getElementsByTagName('div');
for(var i=0;i<odiv.length;i++){
odiv[i].alpha=100;
odiv[i].timer=null;
odiv[i].onmouseover=function(){
startmove(this,30);
}
odiv[i].onmouseout=function(){
startmove(this,100);
}
}
}
function startmove(obj,itarget){
clearInterval(obj.timer);
obj.timer=setInterval(function(){
var speed=0;
if(obj.alpha>itarget)
{
speed=-10;
}
else{
speed=10;
}
if(obj.alpha== itarget){
clearInterval(obj.timer);
}
else{
obj.alpha+=speed;
obj.style.filter='alpha(opacity:'+obj.alpha+')';//IE浏览器
obj.style.opacity=obj.alpha/100;//火狐和chrome浏览器
}
},30)
}
</script>
</head>
<body >
<div id ="div1"></div>
<div id ="div2" ></div>
<div id ="div3"></div>
</body>
</html>
多物体改变透明度的运动
最新推荐文章于 2021-10-05 22:04:01 发布