各位大神,求解,為什么圖片不能邊寬,謝謝!??!
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>baiyechuang</title>
<style type="text/css">
img{
width: 600px;
height: 310px;
}
</style>
</head>
<body>
<img src="1.jpg">
<img src="2.jpg">
<img src="3.jpg">
<img src="4.jpg">
<script type="text/javascript">
window.onload = function (){
var oimg=document.getElementsByTagName('img'),
timer=null;
for(var i=0;i<oimg.length;i++){
function start(target){
var speend=0;
if(target>this.style.width){
speend=1;
}else{
speend=-1;
}
if(this.style.width==target){
clearInterval(timer);
}else{
this.style.width=this.offsetWidth+speend+'px';
}
}
oimg[i].onmouseover=function(){
clearInterval(timer);
timer=setInterval(
start(400);
},30);
}
oimg[i].onmouseout=function(){
clearInterval(timer);
timer=setInterval(
start(310);
},30);
}
}
}
</script>
</body>
</html>
2015-10-15
定時(shí)器沒(méi)有你那么寫(xiě)的吧。里面是一個(gè)匿名回調(diào)函數(shù)
oimg[i].onmouseover=function(){
?? ??? ??? ??? ??? ??? ??? ?
?? ??? ??? ??? ??? ??? ??? ?clearInterval(timer);
?? ??? ??? ??? ??? ??? ??? ?
?? ??? ??? ??? ??? ??? ??? ?timer=setInterval(
?? ??? ??? ??? ??? ??? ??? ?
?? ??? ??? ??? ??? ??? ??? ?start(400);
?? ??? ??? ??? ??? ??? ??? ?
?? ??? ??? ??? ??? ??? ??? ?},30);
仔細(xì)看,{} 明顯的嵌套不對(duì)