标签: jquery
如何阻止用户将元素拖到窗口外?
elm.css({ top : $(window).scrollTop() + ($(window).height() - elm.height()) / 2+'px', left : ($(window).width() - elm.width()) / 2+'px' }) .draggable({ handle : tr_top });
答案 0 :(得分:15)
您可以使用containment选项:
elm.draggable({ handle: tr_top, containment: "window" });