第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定

我按照老師的思路寫的,內(nèi)容也沒區(qū)別,但是在最后obj.style.left的時候一直報錯顯示obj.style未定義是為什么,我代碼在下面,就大神解惑

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>Document</title>

<style type="text/css">



*{padding:0;margin:0;}

ul,li{

list-style:none;

}

ul li{

width:200px;

height: 100px;

background: yellow;

margin-bottom:20px;

}

</style>

<script>

window.onload=function(){



var oLi=document.getElementsByTagName('li');

for(var i=0,l=oLi.length;i<l;i++){

this.onmouseover=function(){

move(this,400);

}

this.onmouseout=function(){

move(this,200);

}

}}

var timer=null;

function move(obj,iTarget){

clearInterval(timer);


timer=setInterval(function(){

var speed=(iTarget-obj.offsetWidth)/2>0?Math.ceil(speed):Math.floor(speed);

if(obj.offsetWidth==iTarget){

clearInterval(timer);

}else{

obj.style.width=obj.offsetWidth+speed+'px';//這里的obj.style一直顯示未定義

}

},50);

}

</script>

</head>

<body>

<ul>

<li></li>

<li></li>

<li></li>

</ul>

</body>

</html>


正在回答

3 回答

參照你的代碼看看,也許對你有幫助


<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>Document</title>

<style type="text/css">



*{padding:0;margin:0;}

ul,li{

list-style:none;

}

ul li{

width:200px;

height: 100px;

background: yellow;

margin-bottom:20px;

}

</style>

<script>

window.onload=function(){
var oLi=document.getElementsByTagName('li');

for(var i=0;i<oLi.length;i++){

oLi[i].onmouseover=function(){/*有改動*/

move(this,400);

}

oLi[i].onmouseout=function(){{/*有改動*/

move(this,200);

}

}}

var timer=null;

function move(obj,iTarget){

clearInterval(timer);


timer=setInterval(function(){
?? ?var speed=(iTarget-obj.offsetWidth)/8;{<!--有改動,原來的那樣寫運算次序有問題-->

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

if(obj.offsetWidth==iTarget){

clearInterval(timer);

}else{

obj.style.width=obj.offsetWidth+speed+'px';//這里的obj沒問題

}

},50);

}

</script>

</head>

<body>

<ul>

<li></li>

<li></li>

<li></li>

</ul>

</body>

</html>

0 回復 有任何疑惑可以回復我~
#1

qq_蘇慕遮_24019744 提問者

非常感謝!
2016-10-09 回復 有任何疑惑可以回復我~

<!DOCTYPE HTML>

<html>

? ? <head>

? ? ? ? <meta charset="utf-8">

? ? ? ? <title></title>

? ? ? ? <style type="text/css">

? ? ? ? ? ? *{

? ? ? ? ? ? ? ? margin: 0px;

? ? ? ? ? ? ? ? padding: 0px;

? ? ? ? ? ? }

? ? ? ? ? ? ul,li{

? ? ? ? ? ? ? ? list-style: 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, Target){

? ? ? ? ? ? ? ? clearInterval(timer);

? ? ? ? ? ? ? ? timer = setInterval(function(){

? ? ? ? ? ? ? ? ? ? var speed = (Target - obj.offsetWidth)/8;

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

? ? ? ? ? ? ? ? ? ? if(obj.offsetWidth == Target){

? ? ? ? ? ? ? ? ? ? ? ? clearInterval(timer);

? ? ? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? ? ? else{

? ? ? ? ? ? ? ? ? ? ? ? obj.style.width = obj.offsetWidth + speed + 'px';

? ? ? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? }, 30)

? ? ? ? ? ? }

? ? </script>

? ? </head>

? ? <body>

? ? ? ? <ul>

? ? ? ? ? ? <li></li>

? ? ? ? ? ? <li></li>

? ? ? ? ? ? <li></li>

? ? ? ? </ul>

? ? </body>

</html>


0 回復 有任何疑惑可以回復我~

首先。

for(var i=0,l=oLi.length;i<l;i++){

this.onmouseover=function(){


這里就不該直接用this,而應該使用

oLi[i].onmouseover=function(){}

因為你遍歷循環(huán)的時候沒指名是哪個object在里面,所以this是屬于window object。而不是具體的某個html元素。




2 回復 有任何疑惑可以回復我~
#1

衣染

還有疑惑的話歡迎追問~互相學習。
2016-10-09 回復 有任何疑惑可以回復我~
#2

劉顏 回復 衣染

如果 <script> 標簽有 "type" 屬性, 其值應為 "text/javascript" 或者 "application/javascript". 另外腳本必須可解析(語法上正確)。 希望可以幫忙解答一下,謝謝
2016-10-31 回復 有任何疑惑可以回復我~
#3

劉顏 回復 衣染

我的代碼貼在下面回復
2016-10-31 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

我按照老師的思路寫的,內(nèi)容也沒區(qū)別,但是在最后obj.style.left的時候一直報錯顯示obj.style未定義是為什么,我代碼在下面,就大神解惑

我要回答 關(guān)注問題
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號