i have a working script, that allows me to scroll inside a -element, while having the mouse pressed and moving it to the left or right.
I want to add vertically scrolling. If I move the mouse to the right or left, i scroll inside the horizontally and if I move the mouse to the top or bottom, it shall scroll vertically.
$(function () {
$('#myDiv').mousedown(function (event) {
$(this)
.data('down', true)
.data('x', event.clientX)
.data('scrollLeft', this.scrollLeft);
return false;
}).mouseup(function (event) {
$(this).data('down', false);
}).mousemove(function (event) {
if ($(this).data('down') == true) {
this.scrollLeft = $(this).data('scrollLeft') + $(this).data('x') - event.clientX;
}
}).css({
'overflow': 'hidden',
'cursor': '-moz-grab'
});
});
$(window).mouseout(function (event) {
if ($('#myDiv').data('down')) {
try {
if (event.originalTarget.nodeName == 'BODY' || event.originalTarget.nodeName == 'HTML') {
$('#myDiv').data('down', false);
}
} catch (e) { }
}
});
Original source: http://jqueryfordesigners.com/fun-with-overflows/
I tried to add
.data('y', event.clientY)
.data('scrollTop', this.scrollTop);
...
this.scrollTop = $(this).data('scrollTop') + $(this).data('y') - event.clientY;
but it is not working for me.
Found this plugin for jquery: https://github.com/iwyg/jquery.dragscroll
With the plugin, it’s possible to scroll horizontal and vertical with the mouse.
Example found here: http://dev.thomas-appel.com/dragscroll/example/
Wonderful idea, but I’ve found some bugs. Hope, that the plugin will be updated.