【发布时间】:2011-05-26 19:46:54
【问题描述】:
我对@987654322@ 很陌生,我正在尝试使用 Draggable 插件创建一个示例页面。页面加载正常,但我无法将我的 <div> 标签拖到任何地方。我一直在尝试复制这个demo。这是我的代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
<style type="text/css">
#draggable { width: 150px; height: 150px; padding: 0.5em; border: solid 1px black; cursor:pointer;}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<script src="scripts/jquery.js" type="text/javascript"/>
<script src="scripts/jquery.ui.core.js" type="text/javascript"/>
<script src="scripts/jquery.ui.draggable.js" type="text/javascript"/>
<script src="scripts/jquery.ui.mouse.js" type="text/javascript"/>
<script src="scripts/jquery.ui.widget.js" type="text/javascript"/>
<script src="scripts/jquery-ui-1.8.13.custom.js" type="text/javascript" />
<script type="text/javascript">
$(document).ready(function() {
$("#draggable").draggable();
});
</script>
<div class="demo" style="height: 500px; width: 500px;">
<div id="draggable">
<p>Drag me around</p>
</div>
</div>
</div>
</form>
</body>
</html>
我只是想实现它,这样我就可以在它周围的“演示”<div> 中拖动我的“可拖动”<div>。谁能看到我错过了什么?
【问题讨论】:
-
看不到代码有任何问题,请确保您已按照 Scott 的建议包含 jQuery UI。还要检查控制台以确保页面前面的 javascript 中没有错误。此外,如果您想将#draggable div 的拖动区域限制为其父级,请使用
$("#draggable").draggable({containment: 'parent'}); -
谢谢。我现在已经添加了它,但它似乎仍然没有任何区别。但最终,这就是我想要的 - 将拖动包含到它的父级
div。 -
只有在可拖动本身工作时才有效。
-
我知道,我想通了。只是想包括它以防万一:)
标签: jquery jquery-ui drag-and-drop draggable jquery-ui-draggable