亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

為什么這個滑塊拖動的時候會閃

為什么這個滑塊拖動的時候會閃

烙印99 2018-09-11 13:13:12
/------------------js部分------------------------- /問題是為什么鼠標拖拽滑塊的時候,滑塊會閃動,求大神指點案例代碼:https://jsfiddle.net/bbux0h7v/2/
查看完整描述

1 回答

?
一只甜甜圈

TA貢獻1836條經驗 獲得超5個贊

offsetY改成pageY就行了。

關于offsetY的意思,規范是這么寫的:

The MouseEvent.offsetY read-only property provides the offset in the Y coordinate of the mouse pointer between that event and the padding edge of the target node.

關于pageY的意思:

The MouseEvent.pageY read-only property returns the vertical coordinate of the event relative to the whole document.

你體會一下這兩者的區別,然后再想想為什么offsetY不行。

最后,個人覺得你的js代碼寫的有點亂……我稍微改了改,你可以參考下:

$(document).ready(function(){    let axiL = 0,
        doc = $(document),
        b = $("#b");    //定義鼠標拖動時執行的函數                    
    function move(event){        const top = parseInt(b.css("top"));        let axiN = top + event.pageY - axiL;
        axiN = (axiN < 0) ? 0: axiN;
        axiN = (axiN > 170) ? 170: axiN;
        b.css("top", axiN);
        axiL = event.pageY;
    }

    b.on("mousedown", function() {
        doc.on("mousemove", move);
        axiL = event.pageY;
    });
    doc.on("mouseup", function() {
        doc.off("mousemove", move);
    });
});


查看完整回答
反對 回復 2018-10-03
  • 1 回答
  • 0 關注
  • 815 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號