[英]Mousedown and mousemove perform inconsistently in Meteor
I have an one page app in Meteor. 我在Meteor中有一个单页应用程序。
I want to track when whether a bookmarklet (in the form of a <a>
tag containing an image) has been dragged towards the bookmarks bar. 我想跟踪何时将小书签(以包含图像的<a>
标记的形式)拖到书签栏。
I'm using a combination of mousedown, mousemove, and mouseup to try to track the drag. 我使用mousedown,mousemove和mouseup的组合来尝试跟踪拖动。
Template.myTemplate.events = {
'mousedown': function(){
Session.set('dragging', true)
console.log('drag starts')
},
'mouseup': function(){
if (Session.get('dragging') == true && event.y < 10){
// The result i want
}
Session.set('dragging', false)
console.log('drag stops')
}
}
The drag starts well enough, but soon after the mouse leaves the <a>
tag it just seems to baulk, and mouseup
doesn't register as it should. 拖动开始足够好,但是在鼠标离开<a>
标记后不久,它似乎就被塞住了,而mouseup
并没有按应有的方式注册。
The logic works as it should if I return false
after mouseup
and mousedown
- ie. 如果我在mouseup
和mousedown
之后return false
,则逻辑将按mouseup
,即。 I can move the mouse far and wide after mousedown, and watch for event.y
being < 10 and there's no baulk - but then the code does not have the desired effect of the user being able to drag the <a>
tag. 按下鼠标后,我可以将鼠标移动到远处,并注意event.y
<10并且没有错误-但是这样的代码并没有达到用户能够拖动<a>
标签的预期效果。
Do you have any ideas? 你有什么想法?
'mousedown': function(){
You're doing mousedown on the template, it should be on the a
element. 您正在将鼠标放在模板上,应该放在a
元素上。
So, do this instead: 因此,改为这样做:
'mousedown a': function(){
Or choose the right a
element here. 或者在这里选择合适a
元素。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.