通过滚动移动 DIV
我正在创建一个 jQuery 滚动条,它滚动
中的内容。它类似于 jQuery ScrollPane。
我已经到了需要移动滚动按钮的地步。我的问题是:在没有任何 UI 插件的情况下,最好的方法是什么?因此,当用户单击滚动按钮时,可以通过 mousedown 事件在其父容器中垂直移动滚动按钮。我怎么能这么做呢?
I'm creating a jQuery scrollbar which scrolls the content in a <div>. It's something like jQuery ScrollPane.
I've come to the point where I need to move the scroll button. My question is: what is the best way to do it without any UI plugin? So when the user clicks on the scroll button it can be moved vertically in its parent container with a mousedown event. How could I do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是一个起点,希望这就是您所追求的:
Here's a starting point, hope that's what you're after:
我只用简单的 JavaScript 开发了一个正确的导航停靠样式项目。
这是链接:
https://github.com/developerDoug/HtmlJavascriptDockInVS2010
使用 ui 插件是最好的如果您能说服您的客户这样做。如果没有,您需要关注的是处理 mousedown 或类似的操作,以注意到移动已经开始。需要重点关注的方法有:mousedown、mousemove、mouseup。
例如,如果在某个 div 上,您检测到 mousedown,您可以调用一个函数,该函数基本上是您的 beginDrag、获取 xy 坐标、保留对开始坐标的引用、attachEvent(如果是 IE)、addEventListener(对于所有其他浏览器)。
前任:
I developed a right nav dock style item with just plain javascript.
Here is the link:
https://github.com/developerDoug/HtmlJavascriptDockInVS2010
Using a ui plugin would be best if you can convince your customer to do so. If not, what you'll need to focus on is hanling mousedown or something similar to that to be noticed that moving has began. The there methods to focus on are: mousedown, mousemove, mouseup.
For example, if on some div, you detect mousedown, you could call a function which basically would be your beginDrag, get x y coordinates, keep a reference to the start coordinates, attachEvent (if IE), addEventListener (for all other browsers).
ex: