Posted in Javascript onAugust 13, 2013
1.导入相应的JS类库:
<script src="http://code.jquery.com/jquery-1.9.1.js"></script> <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
2.带有id的div元素:
<div id="draggable"> <p>Drag me around!</p> </div>
3:设置div的样式:
#draggable { width:150px; height:150px; padding:0.5em; border:1px solid; }
4:让元素可拖动:
<script> $(function() { $('#draggable').draggable(); }); </script>
效果请点击:http://jsfiddle.net/tounaobun/KS8JC/
源代码:
<!-- import the necessary files --> <script src="http://code.jquery.com/jquery-1.9.1.js"></script> <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script> <script> $(function() { $('#draggable').draggable(); }); </script> <style> #draggable { width:150px; height:150px; padding:0.5em; border:1px solid; } </style> <div id="draggable"> <p>Drag me around!</p> </div>
让元素在网页中可拖动示例代码
声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Reply on: @reply_date@
@reply_contents@