感覺我和老師寫的差不多啊怎么這么大問題啊,定時(shí)器還是一個(gè)感覺。。。大神幫我看下
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>多物體運(yùn)動(dòng)</title>
<style type="text/css">
*{margin:0;padding:0;}
ul{
?? ?width:600px;
?? ?height:600px;
?? ?border:1px solid #000;
?? ?list-style:none;
}
li{
?? ?width:60px;
?? ?height:100px;
?? ?background:#F00;
?? ?display:block;
?? ?float:left;
?? ?margin:auto 0px auto 20px;
}
</style>
<script type="text/javascript">
window.onload=function(){
?? ?var aLi=document.getElementsByTagName('li');
?? ?
?? ?for(var i=0;i<aLi.length;i++){
?? ??? ?aLi[i].timer=null;
?? ??? ?aLi[i].onmouseover=function(){
?? ??? ??? ?startMove(this,400);
?? ??? ?};
?? ??? ?aLi[i].onmouseout=function(){
?? ??? ??? ?startMove(this,100)
?? ??? ?};
?? ?};
};
//var timer=null;
function startMove(obj,iTarget){
?? ?
?? ?clearInterval(obj.timer);
?? ?speed=(iTarget-obj.offsetHeight)/10;
?? ?speed=speed>0?Math.ceil(speed):Math.floor(speed);
?? ?obj.timer=setInterval(function(){
?? ??? ?if(obj.offsetHeight==iTarget){
?? ??? ??? ?clearInterval(obj.timer);
?? ??? ?}
?? ??? ?else{
?? ??? ??? ?obj.style.height=obj.offsetHeight+speed+'px';
?? ??? ?}
?? ?},30)
};
</script>
</head>
<body>
<ul>
?? ?<li></li>
??? <li></li>
??? <li></li>
??? <li></li>
??? <li></li>
??? <li></li>
??? <li></li>
</ul>
</body>
</html>
2022-03-25
感謝支持,請(qǐng)繼續(xù)關(guān)注慕課是的,這個(gè)svn服務(wù)是我搭建在服務(wù)器上的,同學(xué)如果想要學(xué)習(xí)使用,搭建在本地也是可以的
2015-12-09
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>多物體運(yùn)動(dòng)</title>
<style type="text/css">
*{margin:0;padding:0;}
ul{
? ? width:600px;
? ? height:600px;
? ? border:1px solid #000;
? ? list-style:none;
}
li{
? ? width:60px;
? ? height:100px;
? ? background:#F00;
? ? display:block;
? ? float:left;
? ? margin:auto 0px auto 20px;
}
</style>
<script type="text/javascript">
window.onload=function(){
? ? var aLi=document.getElementsByTagName('li');
? ??
? ? for(var i=0;i<aLi.length;i++){
? ? ? ? aLi[i].timer=null;
? ? ? ? aLi[i].onmouseover=function(){
? ? ? ? ? ? startMove(this,400);
? ? ? ? };
? ? ? ? aLi[i].onmouseout=function(){
? ? ? ? ? ? startMove(this,100)
? ? ? ? };
? ? };
};
//var timer=null;
function startMove(obj,iTarget){
? ??
? ? clearInterval(obj.timer);
? ??
? ? obj.timer=setInterval(function(){
? ? ? ? if(obj.offsetHeight==iTarget){
? ? ? ? ? ? clearInterval(obj.timer);
? ? ? ? }
? ? ? ? else{
? ? ? ? speed=(iTarget-obj.offsetHeight)/10;
? ? ? ? speed=speed>0?Math.ceil(speed):Math.floor(speed);
? ? ? ? obj.style.height=obj.offsetHeight+speed+'px';
? ? ? ? }
? ? },30)
};
</script>
</head>
<body>
<ul>
? ? <li></li>
? ? <li></li>
? ? <li></li>
? ? <li></li>
? ? <li></li>
? ? <li></li>
? ? <li></li>
</ul>
</body>
</html>
這樣就對(duì)了,把speed變化的代碼寫在定時(shí)器內(nèi)部。