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

為了賬號(hào)安全,請及時(shí)綁定郵箱和手機(jī)立即綁定

如果瀏覽器不支持小數(shù)像素,var speed = (iTarget - oDiv.offsetLeft)/20;當(dāng)speed等于20以下的時(shí)候,oDiv.style.left = oDiv.offsetLeft + speed +'px';這里的speed就小于1了。瀏覽器應(yīng)該在20px左右的時(shí)候就停止了,為什么是在10px左右的時(shí)候停止呢

<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8">

<title></title>

<style type="text/css">

body,div,span{

margin: 0;

padding: 0;

}

? ?#div1{

? ? width: 200px;

? ? height: 200px;

? ? left: -200px;

? ? background-color: red;

? ? position: relative;

? ?}

#div1 span{

width: 20px;

height: 50px;

background-color: blue;

position: absolute;

top:75px;

left: 200px;

}

</style>

<script type="text/javascript">

window.onload = function(){

var oDiv = document.getElementById('div1');

oDiv.onmouseover = function () {

startMove(0);

}

oDiv.onmouseout = function () {

startMove(-200);

}

}


var timer = null;

function startMove(iTarget) {

clearInterval(timer);

var oDiv = document.getElementById('div1');

timer = setInterval(function () {

var speed = (iTarget - oDiv.offsetLeft)/20;

if (oDiv.offsetLeft == iTarget) {

clearInterval(timer);

} else {

oDiv.style.left = oDiv.offsetLeft + speed +'px';

}

},30)

}

</script>

</head>

<body>

<div id="div1">

<span id="share">分享</span>

</div>

</body>

</html>

如果瀏覽器不支持小數(shù)像素,var speed = (iTarget - oDiv.offsetLeft)/20;當(dāng)speed等于20以下的時(shí)候,oDiv.style.left = oDiv.offsetLeft + speed +'px';這里的speed就小于1了。瀏覽器應(yīng)該在20px左右的時(shí)候就停止了,為什么是在10px左右的時(shí)候停止呢

正在回答

2 回答

我猜是因?yàn)橄袼赜行?shù)時(shí)會(huì)四舍五入,所以speed小于1大于0.5時(shí)還會(huì)動(dòng),10px左右的時(shí)候停止是剛好speed在0.5的分界線

1 回復(fù) 有任何疑惑可以回復(fù)我~
#1

慕斯7571954 提問者

非常感謝!
2016-09-20 回復(fù) 有任何疑惑可以回復(fù)我~

看教程

0 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消

如果瀏覽器不支持小數(shù)像素,var speed = (iTarget - oDiv.offsetLeft)/20;當(dāng)speed等于20以下的時(shí)候,oDiv.style.left = oDiv.offsetLeft + speed +'px';這里的speed就小于1了。瀏覽器應(yīng)該在20px左右的時(shí)候就停止了,為什么是在10px左右的時(shí)候停止呢

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

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

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

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