$(document).ready(function() {
var $content = $('.forScroll');
var isDown = false;
var startX, startY, scrollLeft, scrollTop;
$content.on('mousedown', function(e) {
isDown = true;
$content.css('cursor', 'grabbing');
startX = e.pageX - $content.offset().left;
startY = e.pageY - $content.offset().top;
scrollLeft = $content.scrollLeft();
scrollTop = $content.scrollTop();
});
$(document).on('mouseup', function() {
isDown = false;
$content.css('cursor', 'grab');
});
$(document).on('mouseleave', function() {
isDown = false;
$content.css('cursor', 'grab');
});
$content.on('mousemove', function(e) {
if (!isDown) return;
e.preventDefault();
var x = e.pageX - $content.offset().left;
var y = e.pageY - $content.offset().top;
var walkX = (x - startX) * 1; //scroll-fast
var walkY = (y - startY) * 1; //scroll-fast
$content.scrollLeft(scrollLeft - walkX);
$content.scrollTop(scrollTop - walkY);
});
});
728x90