使 jQuery-ui 可拖动手柄覆盖整个页面
单击窗口中任意位置时使元素可拖动的最佳方法是什么?
我是否必须使用覆盖整个窗口的容器
?我尝试使 body
可拖动,但这不起作用。
使用容器
的问题是它会移动,因此在拖动后不再覆盖整个屏幕。制作一个非常巨大的容器
怎么样?它在各个方向上跨越大量像素,这样您就永远不会到达它的边缘。这是一个坏主意吗?这个想法(简化)是有一个中间有一个正方形的页面,可以通过拖动窗口的任何部分来拖动该正方形。
这是一个非常不必要的模型:)
我正在尝试使用全屏 div,但是当我重置它时,其中的元素会随之移回.. http ://jsfiddle.net/LUFf6/
What would be the best way to make an element draggable when clicking anywhere in the window?
Would I have to use a container <div>
that covers the whole window?
I tried making the body
draggable but that didn't work.
The problem with using a container <div>
is that it moves and therefore doesn't cover the whole of the screen any more after it has been dragged.
What about making a really vast container <div>
that spans a large number of pixels in every direction so you would never get to the edge of it. Is that a bad idea?
The idea (simplified) is to have a page with a square in the middle that can be dragged by dragging any part of the window.
Here's a wonderfully unnecessary mockup :)
I'm trying with a full screen div, but when I reset it, the element within it moves back with it.. http://jsfiddle.net/LUFf6/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
编辑:修改为包括鼠标距 div 的偏移量。
EDIT: revised to include mouse offset from the div.
这实际上取决于您想要实现的目标,因此我们需要了解更多。
您可以在每次“放置”事件后将可拖动的 div 移动到屏幕的左上角和全宽/高度吗?
不过,我个人不会走“大容器”路线。
it really depends on what you are trying to achieve, so we'll need to know a bit more really.
You could just move the draggable div to the top left of the screen and full width/height after each "drop" event?
I personally wouldn't go down the 'vast container' route though.