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

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

為什么一定要用math.ceil向上取整才正確?


<!DOCTYPE html>
<html lang="en">
<head>
? ?<meta charset="UTF-8">
? ?<title>緩沖動(dòng)畫效果</title>
? ?<style type="text/css">
#div1{
? ? ? ? ? ?width: 200px;
? ? ? ? ? ?height: 200px;
? ? ? ? ? ?position: absolute;
? ? ? ? ? ?top: 0px;
? ? ? ? ? ?left: -200px;
? ? ? ? ? ?background-color: #b10d1c;
? ? ? ?}
? ? ? ?#share{
? ? ? ? ? ?width: 30px;
? ? ? ? ? ?height: 50px;
? ? ? ? ? ?position: absolute;
? ? ? ? ? ?left: 200px;
? ? ? ? ? ?top: 75px;
? ? ? ? ? ?background-color: #3c6dcb;
? ? ? ? ? ?color: #ffffff;
? ? ? ? ? ?text-align: center;
? ? ? ? ? ?cursor: pointer;
? ? ? ?}
? ?</style>
? ?<script type="text/javascript">
window.onload=function () {
var odiv1=document.getElementById('div1'),
share=document.getElementById('share');
odiv1.onmouseover=function(){
startMove(10,0);
? ? ? ? ? ?}//最好使用匿名函數(shù)來(lái)調(diào)用函數(shù)
// ? ? ? ? ? ?odiv1.onmouseout="startMove(10,0)";
odiv1.onmouseout=function(){
startMove(10,-200);
? ? ? ? ? ?}
var timer=null
? ? ? ? ? ?function startMove(speed,itarget) {
clearInterval(timer);
timer=setInterval(function () {
speed=(itarget-odiv1.offsetLeft)/10;
if(odiv1.offsetLeft==itarget){
clearInterval(timer)
? ? ? ? ? ? ? ? ? ?}
else {
if(odiv1.offsetLeft>itarget){
speed=(odiv1.offsetLeft-itarget)/10;
// ? ? ? ? ? ? ? ? ? ? ? ? ? ?speed=speed>0?Math.ceil(speed):Math.floor(speed);
speed=Math.ceil(speed);
odiv1.style.left=odiv1.offsetLeft+(-speed)+'px';
? ? ? ? ? ? ? ? ? ? ? ?}
else{
speed=(itarget-odiv1.offsetLeft)/10;
// ? ? ? ? ? ? ? ? ? ? ? ? ? ?speed=speed>0?Math.ceil(speed):Math.floor(speed);
speed=Math.ceil(speed);
odiv1.style.left=odiv1.offsetLeft+speed+'px';
? ? ? ? ? ? ? ? ? ? ? ?}


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

</script>
</head>
<body>
<div id="div1"><span id="share">分享</span> </div>
</body>
</html>



正在回答

1 回答

如果(目標(biāo)值-當(dāng)前值)/10 ?不能整除的話。運(yùn)動(dòng)到最后,是1~9之間的數(shù)字來(lái)除以10,結(jié)果是個(gè)小于1的小數(shù),如果向下取整,那就是0,speed=0,意味著不再發(fā)生變化。也就是說(shuō),如果用Math.floor(speed),最后不到10個(gè)像素的時(shí)候,就不會(huì)動(dòng)了。

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

Zohar 提問者

非常感謝!
2016-06-01 回復(fù) 有任何疑惑可以回復(fù)我~
#2

小西瓜籽

執(zhí)行一次后 offsetLeft=-190 那 190/20=9.5 也不是整數(shù) 不加下面取整代碼時(shí),程序一直執(zhí)行到offsetLeft=-10時(shí)才不能執(zhí)行是為什么,求解答
2016-06-23 回復(fù) 有任何疑惑可以回復(fù)我~
#3

飛舞的墨 回復(fù) 小西瓜籽

得到小數(shù)之后,小數(shù)再除小數(shù),后面的數(shù)簡(jiǎn)直是沒法說(shuō)了。反正我用代碼沒找出一點(diǎn)規(guī)律,反而內(nèi)存溢出了。
2016-06-24 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消

為什么一定要用math.ceil向上取整才正確?

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

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

幫助反饋 APP下載

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

公眾號(hào)

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