2015-05-12 63 views
1

我寫了一個叫做dragscroll的角度指令,它通過在畫布上拖動來向右或向左滾動水平溢出元素。Angular Directive ScrollLeft on Drag Bug

請參閱本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. 

但是有一個bug。

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. 

請幫忙。

+0

似乎有與默認的'滾動event'之外的瀏覽器窗口的行爲的東西。您嘗試在'horizo​​ntalScroll'方法中添加'e.preventDefault()'來查看它是否正常工作。 – themyth92

+0

太棒了!非常感謝@ themyth92。請把它作爲答案。我會接受它。我在第一行的dragStart事件函數中添加了e.preventDefault()。這工作。 –

+0

添加爲答案。謝謝 :) – themyth92

回答

1

這個問題似乎是因爲windows瀏覽器以外的默認行爲scrolling event。你可以做的是停止這個默認行爲通過在你的horizontalScroll方法中加入e.preventDefault()

Working fiddle