Javascript 多物体透明度变化
Posted 梁大爷
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Javascript 多物体透明度变化相关的知识,希望对你有一定的参考价值。
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style>
div{
width: 150px;
height: 150px;
background: red;
filter:alpha(opacity:30);
opacity: 0.3;
margin: 5px;
float: left;
}
</style>
<script>
window.onload = function(){
var mydiv = document.getElementTagName(‘div‘);
for(var i=0;i<mydiv.length;i++){
mydiv[i].timer = null;
mydiv[i].alpha = 30;
mydiv[i].onmouseover = function(){
starmove(this,100);
};
mydiv[i].onmouseout = function(){
starmove(this,30);
};
}
};
function starmove(obj,target){
clearInterval(obj.timer);
timer = setInterval(function(){
var speed = (target-obj.alpha)/6;
speed = speed>0?Math.ceil(speed):Math.floor(speed);
if(obj.alpha == target){
clearInterval(timer);
}else{
obj.alpha = obj.alpha + speed;
obj.style.filter = alpha(opacity:obj.alpha);
obj.style.filter = obj.alpha/100;
}
},30);
}
</script>
</head>
<body>
<div></div>
<div></div>
<div></div>
<div></div>
</body>
</html>
以上是关于Javascript 多物体透明度变化的主要内容,如果未能解决你的问题,请参考以下文章