Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
467 views
in Technique[技术] by (71.8m points)

javascript - 边缘在mouseleave / mouseenter上看不到按钮按下(Edge does not see button press on mouseleave / mouseenter)

Left mouse button was pressed or not - Edge always shows .buttons and .button as 0 .(鼠标左键按下与否- Edge总是显示.buttons.button0。)

.which is always 1 .(.which始终为1。) Other browsers work fine.(其他浏览器工作正常。) Other events like click work fine in Edge too.(其他事件(如clickEdge也能正常工作。) Trouble is with mouseleave and mouseenter .(麻烦在于mouseleavemouseenter 。)

So how can I detect in Edge on mouseleave event if left mouse button was pressed or not?(因此,如果没有按下鼠标左键,如何在发生mouseleave事件时在Edge进行检测?)

在此处输入图片说明

PS I can solve it with ugly flag like " isClicked " and update it in all related events like mousedown , mouseup .(PS我可以用丑陋的标志,如“解决它isClicked ”,并在所有相关的活动,如更新mousedownmouseup 。)

But it is ugly and bug prone.(但这是丑陋且容易出错的。)   ask by Alex Vovchuk translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The #1 best answer: Tell your users that you do not support MS Edge.(最佳答案#1:告诉您的用户您不支持MS Edge。)

If that is not an option, then you'll need to track the mouse button status yourself, like(如果这不是一个选项,那么您需要自己跟踪鼠标按钮的状态,例如)

var leftPressed;

function init() {
  document.body.addEventListener("mousedown mouseup") {
    //update leftPressed
  }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.8k users

...