jQuery 可拖动元素
如何保存可拖动元素,以便下次加载它时,无需再次发出 draggable()
函数。
我认为拥有类 ui-draggable 会自动使元素被识别为可拖动,但我发现情况并非如此。
这是保存的draggble 元素。
<div id="one" class="ui-draggable">test 1 </div>
我是否必须再次发出draggable()函数才能使其可拖动。
How do i save a draggable element so the next time i load it, i don't have to issue the draggable()
function again.
I thought having the class ui-draggable
will automatically make the element get recognized as draggable but i see that's not the case.
This is the saved draggble element.
<div id="one" class="ui-draggable">test 1 </div>
Do i have to issue the draggable() function again to make it draggable.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
简短的回答是:是的,每次页面加载时都必须调用draggable。我只会在就绪事件中调用它。这是典型的做法。
The short answer is: Yes, you have to call draggable every time the page loads. I would just call it in the ready event. That's the typical way to do it.
你总是必须发出draggable()。我建议坚持 FishBasket 的回应,然后就去做。
你必须再次这样做的原因是因为它是行为而不是内容。所以这是用JS完成的,而不是HTML。保存 HTML 对您没有帮助,并且您无法“保存”JS 执行 - 您只需要再次运行它。
如果您是受虐狂,您可以通过在鼠标悬停时使用实时事件/委托来对页面上的所有可拖动对象集体执行此操作。但我不建议使用实时鼠标悬停,因为这对于旧浏览器来说是一个性能问题。
这将延迟元素的可拖动调用,直到您将鼠标悬停在该元素上。问题是现在你必须检查鼠标悬停时的每个元素以查看是否进行可拖动调用...
You always have to issue the draggable(). I would suggest sticking with FishBasket's response and just doing it.
The reason you have to do it again is because it's behavior - not content. So it's done with JS, not HTML. Saving the HTML doesn't help you, and you can't "save" the JS execution - you just have to run it again.
If you're masochistic, you can do it collectively for all your draggables on the page though using a live event / delegate on mouseover. But I wouldn't recommend a live mouseover as it's a performance concern for older browsers.
This will delay the draggable call for an element until you mouseover that element. The problem is now you have to check EVERY element onmouseover to see whether to do the draggable call...