If I understand your requirements correctly, you can do this by finding the current position of the drag object when moving it, and then using these values ββto set the background-position background screen , providing a kind of x-backup effect.
var imageOffset = { top: 30, left: 32 }; $(function() { var screenHeight = $('body').height() - 300; // 300: moa height $(".screen").css('background-position', -(imageOffset.left) + 'px ' + -(screenHeight + imageOffset.top) + 'px'); $(".mao").draggable({ axis: "x", drag: function(event, ui) { $(".screen").css('background-position', -(ui.position.left + imageOffset.left) + 'px ' + -(ui.position.top + imageOffset.top) + 'px'); } }); })
Codepen example: http://codepen.io/anon/pen/JWxwzK?editors=0000
You can also use the same code snippet to limit the hand to the left / right borders of the screen. Here is an example of code that can be done in official docs: http://api.jqueryui.com/draggable/#event-drag
source share