我目前正在开发一个拖放插件。(我创建它是因为我希望其他人使用它)并且我想创建containment
像jQuery draggable has it 这样的功能。
我正在尝试以下代码:
var $div = $(o.containment);
$(oj).bind("dragstart", function (ev, dd) {
dd.limit = $div.offset();
dd.limit.bottom = dd.limit.top + $div.outerHeight() - $(this).outerHeight();
dd.limit.right = dd.limit.left + $div.outerWidth() - $(this).outerWidth();
}).bind('drag', function (ev, dd) {
$(this).css({
top: Math.min(dd.limit.bottom, Math.max(dd.limit.top, dd.offsetY)),
left: Math.min(dd.limit.right, Math.max(dd.limit.left, dd.offsetX))
});
});
关于代码:o.containment
, 只是containment
选项的值,在这种情况下是:'#hi'。这应该是oj
插件的选择器应该保留的容器。
问题:(oj
选择器)没有拖动。我希望有人可以帮助我,谢谢。