继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

JQueryUI-拖动(Draggable)-在DOM 元素中约束运动

慕仔4209126
关注TA
已关注
手记 304
粉丝 69
获赞 305

定义和用法

通过定义 draggable 区域的边界来约束每个 draggable 的运动,使用 containment 选项来指定一个父级的 DOM 元素或者一个 jQuery 选择器


示例

<!DOCTYPE html><html><head>	<meta charset="utf-8">	<meta http-equiv="X-UA-Compatible" content="IE=edge">	<title>draggable</title>	<link rel="stylesheet" href="js/jquery-ui-1.12.1.custom/jquery-ui-1.12.1.custom/jquery-ui.min.css">	<style>		.draggable{			width: 90px;			height: 90px;			padding: 0.5em;			float: left;			margin: 0 10px 10px 0;			cursor: move		}		h3{			clear:left;		}		#containment-wrapper{			width:95%;			height: 450px;			border:2px solid #ccc;			padding:10px;		}	</style></head><body>	<h3>在DOM 元素中约束运动:</h3>	<div id="containment-wrapper">		<div id="draggable1" class="draggable ui-widget-content">			<p>我被约束在盒子里</p>		</div>		<div class="draggable ui-widget-content">			<p id="draggable2" class="ui-widget-header">我被约束在父元素内</p>		</div>	</div>	<script src="js/jquery-ui-1.12.1.custom/jquery-ui-1.12.1.custom/external/jquery/jquery.js" type="text/javascript" ></script>	<script src="js/jquery-ui-1.12.1.custom/jquery-ui-1.12.1.custom/jquery-ui.min.js"></script>	<script>		$("#draggable1").draggable({			containment:"#containment-wrapper",			scroll:false		});		$("#draggable2").draggable({containment:"parent"});	</script></body></html>


打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP