我的為什么實現(xiàn)不了,感覺沒有什么問題呀
<style type="text/css">
*{margin:0;padding:0;}
ul,li{
list-style:none;
}
ul li{
width:200px;
height:100px;
background:yellow;
margin-bottom:20px;
}
</style>
<script type="text/javascript">
window.onload=function(){
var lis=document.getElementsByTagName("li");
for(var i=0;i<lis.length;i++){
//lis[i].timer=null;
lis[i].onmouseover=function(){
startMove(this,400);
}
lis[i].onmouseout=function(){
startMove(this,200);
}
}
}
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(timer);
}else{
obj.style.Width=obj.offsetWidth+speed+"px";
}
},30)
}
</script>
</head>
2016-06-06
倒數(shù)第六行obj.style.Width=obj.offsetWidth+speed+"px";中前面Width大寫了,改成小寫即可
2016-05-29
有可能是js的大括號沒配對好,我的就是這樣,你自己打開開發(fā)者工具看看出錯在哪行就知道了 ? ?報錯:Uncaught SyntaxError: Unexpected end of input
2016-05-26
clearInterval(timer); timer改成obj.timer