$(".chat-wrapper > li.draggable") .on('mousemove',function(){ // Update containment each time it dragged $(this).draggable({ greedy: true, handle: '.chat-button', containment: // Set containment to current viewport [$(document).scrollLeft(), $(document).scrollTop(), $(document).scrollLeft()+$(window).width()-$(this).outerWidth(), $(document).scrollTop()+$(window).height()-$(this).outerHeight()] }); }) .draggable({ scroll: false });
source share