久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

原生拖動事件后如何獲取 mouseup 事件?

How to get mouseup event after native drag event?(原生拖動事件后如何獲取 mouseup 事件?)
本文介紹了原生拖動事件后如何獲取 mouseup 事件?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

WHATWG 拖放的實現支持dragstartdragdragend 事件.

The implementation of the WHATWG drag and drop supports dragstart, drag and dragend events.

dragend 事件在可拖動對象返回到原始位置時觸發,例如嘗試盡可能地拖動紅色框并釋放它.dragend (和END!" console.log 消息)將不會觸發,直到可拖動元素返回到原始位置(這在 Safari 瀏覽器中最明顯).

The dragend event fires when the draggable object returns to the original position, e.g. try dragging the red box as far as you can and release it. The dragend (and "END!" console.log message) will not fire until the draggable element returns to the original position (this is most visible in the Safari browser).

var handle = document.querySelector('#handle');

handle.addEventListener('dragend', function () {
    console.log('END!');
});

#handle {
    background: #f00; width: 100px; height: 100px;
}

<div id="handle" draggable="true"></div>

我如何捕獲 mouseup 或任何其他表明拖動手柄釋放的事件沒有延遲?

How do I capture the mouseup or whatever else event that would indicate the release of the drag handle without a delay?

我嘗試過以下幾種變化:

I have tried variations of:

var handle = document.querySelector('#handle');

handle.addEventListener('dragend', function () {
    console.log('END!');
});

handle.addEventListener('mouseup', function () {
    console.log('Mouseup');
});

#handle {
    background: #f00; width: 100px; height: 100px;
}

<div id="handle" draggable="true"></div>

雖然,mouseup"在 dragstart 之后不會觸發.

Though, "mouseup" does not fire after dragstart.

我最接近找到在釋放句柄后立即觸發的事件是 mousemove:

The closest I got to finding an event that would fire instantly after the release of the handle is mousemove:

var handle = document.querySelector('#handle');

handle.addEventListener('dragend', function () {
    console.log('END!');
});

window.addEventListener('mousemove', function () {
   console.log('I will not fire during the drag event. I will fire after handle has been released and mouse is moved.'); 
});

#handle {
    background: #f00; width: 100px; height: 100px;
}

<div id="handle" draggable="true"></div>

問題是這種方法需要用戶移動鼠標.

The problem is that this approach requires user to move the mouse.

推薦答案

解決方法是在 document.body 上啟用 drop:

The workaround is to enable drop on the document.body:

// @see https://developer.mozilla.org/en-US/docs/Web/Events/dragover
document.body.addEventListener('dragover', function (e) {
    // Prevent default to allow drop.
    e.preventDefault();
});

document.body.addEventListener('drop', function (e) {
    // Prevent open as a link for some elements.
    e.preventDefault();
});

使 document.body 監聽 drop 事件導致 dragend 認為您將在釋放時將元素移動到新位置手柄.因此,句柄釋放和dragend之間沒有延遲.

Making document.body to listen for the drop event results in dragend thinking that you will move the element to the new position upon releasing the handle. Therefore, there is no delay between handle release and dragend.

這篇關于原生拖動事件后如何獲取 mouseup 事件?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How can I get my jasmine tests fixtures to load before the javascript considers the document to be quot;readyquot;?(在 javascript 認為文檔“準備好之前,如何讓我的 jasmine 測試裝置加載?) - IT屋-程序員軟件開發技術
What do jasmine runs and waitsFor actually do?(jasmine 運行和等待實際上是做什么的?)
How to provide mock files to change event of lt;input type=#39;file#39;gt; for unit testing(如何提供模擬文件來更改 lt;input type=filegt; 的事件用于單元測試)
How to unit test a chained method using Jasmine(如何使用 Jasmine 對鏈式方法進行單元測試)
How do I inject $rootScope into an AngularJS unit test?(如何將 $rootScope 注入 AngularJS 單元測試?)
Jasmine - How to spy on a function call within a function?(Jasmine - 如何監視函數中的函數調用?)
主站蜘蛛池模板: 看真人视频一级毛片 | 日韩精品一区二区三区 | 日韩一区二区三区视频在线观看 | 成人在线视频免费观看 | 国产亚洲精品a | 成人免费视频网站在线观看 | 综合网视频 | 视频在线观看一区二区 | 欧美一级二级视频 | 亚洲精品色| 91在线电影| 欧美一区二区免费 | 精品一区av | 一级片av| 天天爱天天操 | 97碰碰碰| 999久久久免费精品国产 | 日韩国产欧美在线观看 | 成人国产免费视频 | 一区二区伦理电影 | 中文字幕亚洲免费 | 亚洲国产一区二区三区在线观看 | 盗摄精品av一区二区三区 | 欧美综合网 | 精品久久久久久久久久久久久 | 欧美成人影院在线 | 欧美激情在线一区二区三区 | 在线观看特色大片免费网站 | 午夜影院在线观看免费 | 国产粉嫩尤物极品99综合精品 | 日韩手机在线看片 | 欧美三级三级三级爽爽爽 | 日日射影院 | 国产精品美女久久久久aⅴ国产馆 | 国产精品高清在线 | 一级少妇女片 | 亚洲狠狠丁香婷婷综合久久久 | 国产福利在线小视频 | 久久久91精品国产一区二区三区 | 久久久久久久成人 | 亚洲国产精品美女 |