[英]How to perform the onlick event even when the div is dragged?
I have a div: 我有一个div:
<div
id="up"
onmousedown="mousedown('url(/scanToUserBox/img/cpt_subfunc_005_prev_p.png)', this)"
onclick="changePage('up')">
</div>
When I press it the onmousedown is triggered, but when I dragged away from the button and remove the click, the onclick event is not triggered. 当我按下它时,onmousedown被触发,但是当我从按钮上移开并删除单击时,不会触发onclick事件。 How can I trigger it without using onmouseout?
如何在不使用onmouseout的情况下触发它? (ondrag is not supported)
(不支持ondrag)
I suggest adding listeners to the div. 我建议将监听器添加到div中。 You can then use it like this:
然后可以像这样使用它:
//get div
var div = document.getElementById('up');
//Define a funcion where you do what you want on mouse release.
//Remove the listener after you are done.
function up() {
//console.log("up")
//do stuff
window.removeEventListener('mouseup', up);
}
div.addEventListener('mousedown', function (e) {
//console.log("down");
//Do stuff
//Call mouseup when you are done with mouse down.
window.addEventListener('mouseup', up);
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.