gpt4 book ai didi

javascript - 拖动 Bug 时向 ScrollLeft 的 Angular Directive(指令)

转载 作者:行者123 更新时间:2023-11-28 17:06:46 28 4
gpt4 key购买 nike

我编写了一个名为 dragscroll 的 Angular Directive(指令),它根据在 Canvas 上的拖动向右或向左滚动水平溢出元素。

请引用这个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.

请帮忙。

最佳答案

问题似乎是因为 滚动事件 在 Windows 浏览器之外的默认行为。您可以做的是通过在 horizo​​ntalScroll 方法中添加 e.preventDefault()停止此默认行为。

Working fiddle

关于javascript - 拖动 Bug 时向 ScrollLeft 的 Angular Directive(指令),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30182864/

28 4 0
文章推荐: javascript - 使用淡入淡出切换
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com