刘颜
2016-10-31 06:57
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
*{
margin: 0px;
padding: 0px;
}
ul,li{
list-style: none;
}
ul li{
width: 200px;
height: 100px;
background:yellow;
margin-bottom:20px;
filter: alpha(opacity:30);
opacity:0.3;
}
</style>
<script type="text/javascript">
window.onload = function(){
var aLi = document.getElementsByTagName('li');
for(var i = 0. i < aLi.length; i++){
aLi[i].alpha = 30;
aLi[i].onmouseover = function(){
startMove(this, 100);
}
aLi[i].onmouseout = function(){
startMove(this, 30);
}
}
}
function startMove(obj, Target){
clearInterval(obj.timer);
obj.timer = setInterval(function(){
var speed = 0;
if(obj.alpha > Taret){
speed = -10;
}
if(obj.alpha < Taret){
speed = 10;
}
if(obj.offsetWidth == Target){
clearInterval(obj.timer);
}
else{
obj.alpha += speed;
obj.style.filter = 'alpha(opacity:' + obj.alpha + ')';
obj.style.opacity = obj.alpha/100;
}
}, 30)
}
/*
window.onload = function(){
var aLi = document.getElementsByTagName('li');
for(var i = 0. i < aLi.length; i++){
aLi[i].onmouseover = function(){
startMove(this, 400);
}
aLi[i].onmouseout = function(){
startMove(this, 200);
}
}
}
//var timer = null;
function startMove(obj, Target){
clearInterval(obj.timer);
obj.timer = setInterval(function(){
var speed = (Target - obj.offsetWidth)/8;
speed = (speed > 0) ? Math.ceil(speed): Math.floor(speed);
if(obj.offsetWidth == Target){
clearInterval(obj.timer);
}
else{
obj.style.width = obj.offsetWidth + speed + 'px';
}
}, 30)
}
*/
</script>
</head>
<body>
<ul>
<li></li>
<li></li>
<li></li>
</ul>
</body>
</html>
兄弟啊,细心点啊。你传参是Target,下面却在用Taret
if(obj.alpha > Target){
speed = -10;
}
if(obj.alpha < Target){
speed = 10;
}
JS动画效果
113925 学习 · 1443 问题
相似问题