我的獲取到的對(duì)象一直是window 代碼如下 移入就會(huì)報(bào)錯(cuò)
<!doctype html>
<html>
<head>
? ? <meta charset="UTF-8">
? ? <title>JS動(dòng)畫2</title>
? ? <style type="text/css">
?ul li {
? ? list-style: none;
? ? width: 200px;
? ?height: 100px;
? ?background: yellow;
? ?margin-bottom: 20px;
}
? ? </style>
</head>
<body>
? <ul>
<li>1</li>
<li>2</li>
<li>3</li>
? </ul>
</body>
? ?<script type="text/javascript">
? ?window.onload=function() {
? ? var lis=document.getElementsByTagName("li");
? ? for(var i=0;i<lis.length;i++){
? ? ? lis[i]=onmouseover=function(){
? ? ? ? Move(this,400);
? ? ? }
? ? ? lis[i]=onmouseover=function(){
? ? ? ? Move(this,200);
? ? ? }
? ? }
? }
? var timer=null;
? function Move(tar,aim) {
? ?clearInterval(timer);
? ?timer=setInterval(function(){
? var sp=(aim-tar.offsetWidth)/8;
? sp=sp>0?Math.ceil(sp):Math.floor(sp);
? ? if(tar.offsetWidth==aim){
? ? ? clearInterval(timer);
? ? }else{
? ? ??
? ? ? tar.offsetWidth=tar.style.width+sp+"px";
? ? }
??
? ?},10);
? }
? ?
?
? ?</script>
</html>
2017-09-22