不會動,代碼一樣,就是不會動
<!DOCTYPE html>
<html>
<head>
?? ?<title>huoqu</title>
</head>
<style type="text/css">
?? ?body,ul,li{
?? ??? ?margin: 0;
?? ??? ?padding: 0;
?? ?}
?? ?ul,li{
?? ??? ?list-style: none;
?? ?}
?? ?ul li{
?? ??? ?width: 200px;
?? ??? ?height: 100px;
?? ??? ?background: blue;
?? ??? ?margin-bottom: 20px;
?? ?}
</style>
<script type="text/javascript">
?? ?window.onload=function(){
?? ??? ?var ai=document.getElementsByTagName('li');
?? ??? ?for(var i=0;i<ali.length;i++){
?? ??? ??? ?ai[i].timer=null;
?? ??? ??? ?ai[i].onmouseover=function(){
?? ??? ??? ??? ?starmove(this,400);
?? ??? ??? ?}
?? ??? ??? ?ai[i].onmouseout=function{
?? ??? ??? ??? ?starmove(this,200);
?? ??? ??? ?}
?? ??? ?}
?? ?}
function starmove(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>
<body>
<ul>
?? ?<li></li>
?? ?<li></li>
?? ?<li></li>
</ul>
</body>
</html>
2016-12-07
ai[i].onmouseout=function(){}少了一個括號 ?好友出現(xiàn)問題 在網(wǎng)頁上右擊檢查元素 ?可以很快發(fā)現(xiàn)問題 望采納
2016-12-04
變量寫錯了
2016-12-02
我也遇到這樣的問題了!代碼一樣,就是不動。
<!DOCTYPE html>
<html>
<head>
<title></title>
<style type="text/css">
*{margin: 0;padding: 0;}
ul,li{list-style-type: none;}
ul li{
width: 200px;
height:100px;
background: yellow;
margin-bottom: 20px;
}
</style>
<script type="text/javascript">
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,iTarget){
clearInterval(timer);
timer=setInterval(function(){
var speed=(iTarget-obj.offsetWidth)/8;
speed=speed>0?Math.ceil(speed):Math.floor(speed);
if(obj.offsetWidth==iTarget){
clearInterval(timer);
}
else{
obj.style.width=obj.offsetWidth+speed+'px';
}
},30)
}
</script>
</head>
<body>
<ul>
<li></li>
<li></li>
<li></li>
</ul>
</body>
</html>
2016-11-29
我放你的代碼進(jìn)去編輯器看了,onmouseout是對的,但是他沒有高亮顯示 你重新打一遍就好,不需要糾結(jié)
附上完整代碼
<!DOCTYPE html>
<html>
<head>
? ? <title>huoqu</title>
</head>
<style type="text/css">
? ? body,ul,li{
? ? ? ? margin: 0;
? ? ? ? padding: 0;
? ? }
? ? ul,li{
? ? ? ? list-style: none;
? ? }
? ? ul li{
? ? ? ? width: 200px;
? ? ? ? height: 100px;
? ? ? ? background: blue;
? ? ? ? margin-bottom: 20px;
? ? }
</style>
<script type="text/javascript">
? ? window.onload=function(){
? ? ? ? var ai=document.getElementsByTagName('li');
? ? ? ? for(var i=0;i<ai.length;i++){
? ? ? ? ? ? ai[i].timer=null;
? ? ? ? ? ? ai[i].onmouseover=function(){
? ? ? ? ? ? ? ? starmove(this,400);
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ai[i].onmouseout=function(){
? ? ? ? ? ? ? ? starmove(this,200);
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ??
? ? }
function starmove(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>
<body>
<ul>
? ? <li></li>
? ? <li></li>
? ? <li></li>
</ul>
</body>
</html>
望采納,晚安
2016-11-29
那個for循環(huán)那個ali寫錯了,單詞
?var ai=document.getElementsByTagName('li');
?? ??? ?for(var i=0;i<ai.length;i++){
?? ??? ??? ?ai[i].timer=null;
?? ??? ??? ?ai[i].onmouseover=function(){
?? ??? ??? ??? ?starmove(this,400);
?? ??? ??? ?}
?? ??? ??? ?ai[i].onmouseout=function{
?? ??? ??? ??? ?starmove(this,200);
?? ??? ??? ?}
?? ??? ?}
2016-11-29
三個li會不會獲取的時候出了問題,你給它們設(shè)個id試試