<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<script src="../public/js/jquery-1.8.3.js"></script>
<script src="../public/js/jquery-ui-1.10.4.custom.js"></script>
<script src="../public/js/jquery-ui.js"></script>
<title>具有对齐功能的拖放</title>
<style type="text/css">
.draggable{width: 150px;height: 150px;background-color: #990}
#contain{margin-left:20px;margin-bottom:20px; width:200px;height:200px;background-color: blue;}
#parent{margin-left:20px;margin-bottom:20px; width:500px;height:500px;background-color:red;}
</style>
<script type="text/javascript">
$(document).ready(function(){
$("#draggable").draggable({snap:true});//在拖放时,捕捉所有的元素,在拖曳时对所有可能目标提供对齐功能
$("#draggable2").draggable({snap:"#parent"});//仅捕到特定容器边缘,拖动时会将目标控件向容器边缘进行对齐
//捕捉特定容器边缘,snapMode指定为outer表示捕捉到外部边缘,仅对齐外边缘
$("#draggable3").draggable({snap:"#parent",snapMode:"outer"});
$("#draggable4").draggable({grid:[20,20]});//以20*20单元格进行捕捉,grid表示按单元格进行对齐定位
$("#draggable5").draggable({grid:[80,80]});//以80*80单元格进行捕捉
});
</script>
</head>
<body>
<div id="parent">
parent控件
<div id="draggable" class="ui-widget-content draggable">
<p>在拖曳时对所有可能目标提供对齐功能</p>
</div>
<div id="draggable2" class="ui-widget-content draggable">
<p>拖动时会将目标控件向容器边缘进行对齐</p>
</div>
<div id="draggable4" class="ui-widget-content draggable">
<p>grid表示按单元格进行对齐定位,[20*20]</p>
</div>
<div id="draggable3" class="ui-widget-content draggable">
<p>拖动时会将目标控件向容器边缘进行对齐,仅对齐外边缘子</p>
</div>
<div id="draggable5" class="ui-widget-content draggable">
<p>grid表示按单元格进行对齐定位,[80*80]</p>
</div>
</div>
</body>
</html>
jQuery具有对齐功能的拖放
最新推荐文章于 2019-04-18 14:34:00 发布