沒(méi)有報(bào)錯(cuò),但是為什么沒(méi)效果?
<!DOCTYPE html>
<html>
<head>
? ? <meta charset="utf-8">
<title>計(jì)時(shí)器</title>
<style type="text/css">
body{margin: 0;padding: 0;}
#box{width: 100px;height: 100px;background-color:yellow;margin: 10px;}
</style>
<script type="text/javascript">
window.onload=function(){
var boxs=document.getElementsByTagName('box');
for (var i = 0; i < boxs.length; i++) {
boxs[i].timer=null;
boxs[i].onmouseover=function(){
goMove(this,300);
?}
? ?boxs[i].onmouseout=function(){
goMove(this,50);
? ? }?
? }?
} ? ??
function goMove(obj,target){
clearInterval(obj.timer);
? ?obj.timer=setInterval(function(){
? ?var speed=(target-obj.offsetWidth)/10;
? ?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>
<div id="box"></div>
<div id="box"></div>
<div id="box"></div>
</body>
</html
2016-09-28
var boxs=document.getElementsByTagName('box');這里錯(cuò)了哦!
2016-08-29
明白了 犯了一個(gè)很愚的錯(cuò)誤