[英]JQuery-UI Draggable locked to the window
I created a really simple map and I wanted it to be dragable. 我创建了一个非常简单的地图,并且希望它可以拖动。
Here is the code: http://jsfiddle.net/AeABp/ 这是代码: http : //jsfiddle.net/AeABp/
It works, I can move the map around how I want. 它可以工作,我可以根据需要移动地图。 But I want it to be locked to the "window", so that there is never white space when it get dragged, I hope you understand what I mean. 但是我希望将其锁定在“窗口”上,以便在拖动时永远不会有空格,希望您理解我的意思。 I also had a look at the the overview from jquery-ui, but didn't find anything that I needed. 我也查看了jquery-ui的概述,但没有找到我需要的任何内容。
You need to constrain movement to a set of coordinates to make it work properly. 您需要将运动限制为一组坐标才能使其正常工作。 Took a bit of messing with, but the containment constrains the element based on the top left corner of the element. 有点混乱,但是包含约束根据元素的左上角对其进行约束。
$(function() {
var con = $('#container');
var cw = con.width( ), ch = con.height( );
var map = $('#map');
var mw = map.width( ), mh = map.height( );
var x1 = -mw + cw, y1 = -mh + ch;
map.draggable({containment:[x1,y1,0,0]});
});
There's an easy way to do it (if i understood well): 有一个简单的方法可以做到(如果我理解的很好):
$('#map').draggable({
containment: 'window',
scroll: false
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.