南柯再续
2016-10-30 16:56
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
body,div{
padding: 0;
margin: 0;
}
#div1{
width: 200px;
height: 200px;
background: red;
filter: alpha(opacity:30);
opacity: 0.3;
}
</style>
<script type="text/javascript">
window.onload=function(){
var oDiv=document.getElementById('div1');
oDiv.onmouseover=function(){
startMove(100);
}
oDiv.onmouseout=function(){
startMove(30);
}
}
var timer=null;
var alpha=30;
function startMove(iTarget){
clearInterVal(timer);
var oDiv=document.getElementById("div1");
timer=setInterVal(function(){
var speed=0;
if (alpha>iTarget) {
speed=-10;
}
if (alpha<iTarget) {
speed=10;
}
if (oDiv.offsetAlpha==iTarget) {
clearInterVal(timer);
}
else{
alpha+=speed;
oDiv.style.filter='alpha(opacity:'+alpha+')';
oDiv.style.opacity=alpha/100;
}
},30)
}
</script>
</head>
<body>
<div id="div1">s</div>
</body>
</html>
没有oDiv.offsetAlpha这个属性,改成alpha就行啦
没有oDiv.offsetAlpha这个属性,像老师讲的那样设置一个全局变量来计数就好了
JS动画效果
113925 学习 · 1443 问题
相似问题