jQuery Draggable drags off screen

2019-04-28 16:15发布

When the user grabs the titlebar of a window and drags to the right all the way, the page will start to scroll right. Is there anyway to prevent this?

To reproduce: https://jqueryui.com/draggable/ Drag the window to the right.

I have overflow: hidden on the html and body tags. Not sure what else to do here. I'd prefer not to use the containment option on the window because I want them to be able to slide off screen slightly.

2条回答
Lonely孤独者°
2楼-- · 2019-04-28 16:57

Try this: Lets say your main element is a div named 'myWindow';

document.getElementById('myWindow').scrolling = "no";
查看更多
男人必须洒脱
3楼-- · 2019-04-28 17:07

When you use jQuery UI Draggable, you have an option called Containment. In that, you can specify the parent, inside which it should be constrained. In your case, the parent should be the body.

As an alternative, you could use the scroll option:

$( "#outlook" ).draggable({ scroll: false });
查看更多
登录 后发表回答