AINIforever
2016-11-13 13:31
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>2</title>
<style type="">
div{
width: 200px;
height: 200px;
margin: 10px;
float: left;
opacity: 0.3;
filter: alpha(opacity:30);
background-color: red;
}
</style>
<script type="text/javascript">
window.onload = function(){
var oDiv = document.getElementByTagName('div');
for (var i = 0; i <oDiv.length; i++) {
var oDiv[i].alpha = 30;
oDiv[i].onmouseover = function(){
startMove(this,100);
}
oDiv[i].onmouseout = function(){
startMove(this,30);
}
}
}
//var timer = null;
//var alpha = 30;
function startMove(obj,iTarget){
//var oDiv = document.getElementById('div1');
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+')';
obj.style.opacity = obj.alpha/100;
}
},30)
}
</script>
</head>
<body>
<div id="div1"></div>
<div id="div2"></div>
<div id="div3"></div>
<div id="div4"></div>
</body>
</html>
兄弟你这里错了:
重复定义?
JS动画效果
113925 学习 · 1443 问题
相似问题