对Drag Bug的ScrollLeft的Angular指令

时间:2015-05-12 05:56:55

标签: javascript jquery html css angularjs

我写了一个名为dragscroll的角度指令,它根据在画布上的拖动来向右或向左滚动水平溢出元素。

请参阅此fiddle

How it works: 
1. Horizontal scroll is at 0.
2. Mousedown at the right end of the div and while holding it
3. Mousemove left 
4. Page scrolls right. 
5. Mouseup stops the dragging.
And Vice versa.

但是有一个错误。

This occurs when
1. the horizontal scrollbar is in the middle of the div, 
2. you "mousedown" on any part of the canvas (pink) part and 
3.  mousemove to the left edge, and hold it,

 the scroll happens continuously, which is not the desired behavior. I have not coded any scrollLeft behavior for this kind of event. Dont know why it is happening. 

请帮忙。

1 个答案:

答案 0 :(得分:1)

问题似乎是因为Windows浏览器之外的scrolling event的默认行为。您可以通过在e.preventDefault()方法中添加horizontalScroll停止此默认行为。

Working fiddle