开发者

Limit drag area of scriptaculous draggable

开发者 https://www.devze.com 2023-01-14 04:34 出处:网络
Im usign this to create a bunch on draggable elements: $$(\'.box\').each( function(item){ new Draggable(item) });

Im usign this to create a bunch on draggable elements:

$$('.box').each( function(item){ new Draggable(item) });

How can I limit the draggable area? This way, the boxes can be droped anywhere on the page, and I would like to 开发者_运维百科limit the drag area to their current parent element (I dont think I need to create a droppable). Or, at least, i would like to revert the box to its initial position if its dropped outside it parent. How can I do this? thanks.


probably a bit late, but here is my solution:

just add a snap to the draggable item

new Draggable('myItem', {
    snap: function(y) {
        return[ (y < 1024) ? (y > 0 ? y : 0) : 1024 ];
    }
});

now your item moves just along x.


If you want to limit the drag horizontal or vertical, you can use this:

new Draggable('myItem', {
    constraint: "horizontal"
    });

Or like bopa said, you can use snap to limit the drag with specifics x y like in this example: http://www.tutorialspoint.com/cgi-bin/practice.cgi?file=scriptaculous_14

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号