0

如何使元素在整个页面上可拖动。现在它只允许我在父 div 中拖动我的元素。

 $(thumb).draggable()

我正在使用这个库:http: //touchpunch.furf.com/

 var thumb = document.createElement("img");
            $(thumb).draggable({containment: "html"});
            thinner.appendChild(thumb);
4

4 回答 4

2

This should work:

$(thumb).draggable({containment: "body"});

Official demo on the containment option

于 2013-02-22T14:12:02.573 回答
1

In addition to containment, you may have to use the appendTo option to have your helper appended to the body while you drag it:

$(thumb).draggable({containment: "body", appendTo: "body"});

http://api.jqueryui.com/draggable/#option-appendTo

于 2013-10-22T22:47:23.857 回答
1

如果要使用$(thumb).draggable({containment: "body"});,则必须将其添加到 CSS 中。

body{
   overflow: hidden;
}

否则使用:

$(thumb).draggable({containment: "html"});

演示(无 CSS):http: //jsbin.com/ukotit/7/edit

演示(使用 CSS):http: //jsbin.com/ukotit/5/edit

于 2013-02-22T16:15:09.353 回答
0

尝试.draggable({containment: "body", scroll: false})

于 2019-06-05T14:51:24.833 回答