慕勒0078764
2017-10-18 10:48
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<style>
body,div{
margin = 0;
padding = 0;
}
div{
height: 200px;
width: 200px;
margin: 20px;
float: left;
background: red;
filter:alpha(opacity:20); /* IE浏览器 */
opacity:0.2; /* 火狐浏览器 */
}
</style>
<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].timer = null;
oDiv[i].onmouseover = function(){
startmove(this,100);
}
oDiv[i].onmouseout = function(){
startmove(this,30);
}
}
}
//var timer = null;
//var alpha = 30;
function startmove(obj,iTarger){
//var oDiv = document.getElementById("div1");
clearInterval(obj.timer);
obj.timer = setInterval(function(){
var speed = 0;
if (obj.alpha > iTarger){
speed = -10;
}
else{
speed =10;
}
if(obj.alpha == iTarger){
clearInterval(obj.timer);
}
else
{
obj.alpha = 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>
</body>
</html>
obj.style.filter = 'alpha(opacity:'+obj.alpha+')';
这句错了,应该是obj.style.filter = 'obj.alpha(opacity:'+obj.alpha+')';
for(var i = 0; i < oDiv.Length; i++) 这句里面的oDiv.Length应该改为oDiv.length.此处应是小写的l.
把Length的L小写
JS动画效果
113925 学习 · 1443 问题
相似问题