猿问

为什么代码运行不出来,求大神

<!DOCTYPE html>

<html>

<head>

<title>任意属性值</title>

<meta charset="utf-8">

<style>

*{

margin:0;

padding:0;

}

ul,li{

list-style: none;

}

#li1{

width: 200px;

height: 100px;

background: yellow;

margin-bottom: 10px;

border: 2px solid red;

}

#li2{

width: 200px;

height: 100px;

background: yellow;

margin-bottom: 10px;

border: 2px solid red;

}

</style>

<script>

window.onload=function(){

var Li1=document.getElementsById('li1');

var Li2=document.getElementsById('li2');

li1.onmouseover=function(){

startMove(this,'height',400);

}

li1.onmouseout=function(){

startMove(this,'height',100);

}

li2.onmouseover=function(){

startMove(this,'width',400);

}

li2.onmouseout=function(){

startMove(this,'width',200);

}

}

function startMove(obj,attr,target){

clearInterval(obj.timer);

  obj.timer=setInterval(function(){

var icur=parseInt(getStyle(obj,attr));

var speed=(target-icur)/8;

speed=speed>0?Math.ceil(speed):Math.floor(speed);

if (icur==target) {

clearInterval(obj.timer);

} else{

obj.style[attr]=icur+speed+'px';

}

},30)

}

function getStyle(obj,attr) {

if (obj.currentStyle) {

return obj.currentStyle[attr];

} else{

return getComputedStyle(obj,false)[attr];

};

}

</script>

</head>

<body>

<ul>

<li id="li1"></li>

<li id="li2"></li>

</ul>

</body>

</html>



FLY_QUEEN
浏览 1286回答 1
1回答

qq_青枣工作室_0

打开控制台,可以看到报错啊var Li1=document.getElementsById('li1');getElementsById多了一个s,其他地方一样
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答