可拖动和可扩展的遏制
我试图授权仅在其遏制的右侧或底部拖出一个对象,并且如果不停止拖动该元素就无法正确执行此操作。
我的代码:
<!DOCTYPE html>
<html>
<head>
<style>
#parent { height: 500px; width: 500px; border: 1px black solid; }
#images { height: 100px; width: 100px; background-color:orange; }
</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.5/jquery-ui.js"></script>
</head>
<body>
<div id="parent">
<div id="images"></div>
</div>
<script>
$(document).ready(function() {
$("#images").draggable({
containment: $("#parent"),
drag: function(event, ui) {
var helper = ui.helper, pos = ui.position;
if(pos.left + parseInt(helper.outerWidth(), 10) == parseInt($("#parent").css("width"), 10)) {
$("#parent").animate({width: "+=100"});
}
if(pos.top + parseInt(helper.outerHeight(), 10) == parseInt($("#parent").css("height"), 10)) {
$("#parent").animate({height: "+=100"});
}
}
});
});
</script>
</body>
</html>
您知道如何刷新容器大小以便继续在右侧或底部拖动吗?
谢谢 !
i'm trying to the authorize to drag out an object only on the right or bottom side of his containment and cannot do it properly whitout stop dragging the element.
My code:
<!DOCTYPE html>
<html>
<head>
<style>
#parent { height: 500px; width: 500px; border: 1px black solid; }
#images { height: 100px; width: 100px; background-color:orange; }
</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.5/jquery-ui.js"></script>
</head>
<body>
<div id="parent">
<div id="images"></div>
</div>
<script>
$(document).ready(function() {
$("#images").draggable({
containment: $("#parent"),
drag: function(event, ui) {
var helper = ui.helper, pos = ui.position;
if(pos.left + parseInt(helper.outerWidth(), 10) == parseInt($("#parent").css("width"), 10)) {
$("#parent").animate({width: "+=100"});
}
if(pos.top + parseInt(helper.outerHeight(), 10) == parseInt($("#parent").css("height"), 10)) {
$("#parent").animate({height: "+=100"});
}
}
});
});
</script>
</body>
</html>
Have you an idea how about refreshing the containment size in order to continue dragging on the right or bottom side ?
Thanks !
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
简单的解决方案(参见DEMO):
Simple solution (see DEMO):