You can use the Scroll option to prevent the page from scrolling.
$( "#draggable" ).draggable({scroll: false });
It can be used together with containment: "parent"
to prevent the box sticking out of its parent.
What seem to be happening with your code is that the page is scrolled when you reach the corner and then never scrolled back as you have overflow: hidden
set for body
.
The downside with using scroll: false
is that you won't be able to drag the element down the page either.
Documentation: http://api.jqueryui.com/draggable/#option-scroll