通过未嵌套的句柄拖动 div
在 JQueryUI 可拖动演示中,我可以看到您可以将句柄附加到 DIV 但如果句柄未嵌套在可拖动的父 DIV 中,它不起作用,例如
<script src="jquery-1.5.2.js"></script>
<script src="js/jquery-ui-1.8.11.custom.min.js"></script>
<style>
#hBlack
{
width:55px;
height:55px;
background-color: black;
top:0px;
}
#hGreen
{
width:25px;
height:25px;
background-color: green;
}
</style>
<script language="javascript" type="text/javascript">
$(function() {
$("#hBlack").draggable({handle:"#hGreen"});
});
</script>
</head>
<body>
<div id="hBlack">
</div>
<div id="hGreen"></div>
上面的内容不会使 #hGreen 成为句柄 - 但以下内容会这样做:
<div id="hBlack">
<div id="hGreen"></div>
</div>
本质上,我试图在另一个 DIV 移动时使一个 DIV 移动 - 我猜你可以使用新的职位实用程序来完成,但对于像我这样的新手,我发现它的记录很少
In the JQueryUI draggable demo, I can see you can attach a handle to a DIV but if the handle is not nested within the parent DIV that is draggable, it doesn't work e.g.
<script src="jquery-1.5.2.js"></script>
<script src="js/jquery-ui-1.8.11.custom.min.js"></script>
<style>
#hBlack
{
width:55px;
height:55px;
background-color: black;
top:0px;
}
#hGreen
{
width:25px;
height:25px;
background-color: green;
}
</style>
<script language="javascript" type="text/javascript">
$(function() {
$("#hBlack").draggable({handle:"#hGreen"});
});
</script>
</head>
<body>
<div id="hBlack">
</div>
<div id="hGreen"></div>
The above doesn't make #hGreen the handle - but the following does:
<div id="hBlack">
<div id="hGreen"></div>
</div>
Essentially, I am trying to make one DIV move when another moves - I guess you can do it with the new Position utility but for a newbie like me I find it poorly documented
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一种可能的解决方案是将手柄放在内部,但使用 css 将其放置在外部。
Javascript:
HTML:
CSS:
否则,您可能必须执行类似于多选可拖动的操作。
如何一次拖动多个元素使用 JavaScript 或 jQuery?
One possible solution could be to have the handle inside, but use css to position it outside.
Javascript:
HTML:
CSS:
Otherwise, you might have to do something similar to a multiselect draggable.
How do I drag multiple elements at once with JavaScript or jQuery?