Skip to content

Instantly share code, notes, and snippets.

@datamosh
Created January 26, 2012 15:41
Show Gist options
  • Save datamosh/1683324 to your computer and use it in GitHub Desktop.
Save datamosh/1683324 to your computer and use it in GitHub Desktop.
jQuery Scroll fix for messiha
$(document).ready(function () {
$('#timeline').mousedown(function (event) {
// Form fix!
var target = $(event.target); if(target.attr('type') != undefined) target.focus();
$(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) * 2; // twice as fast
}
}).mousewheel(function (event, delta) {
this.scrollLeft -= (delta * 30);
}).css({
'overflow' : 'hidden',
'cursor' : '-moz-grab'
});
});
$(window).mouseout(function (event) {
if ($('#timeline').data('down')) {
try {
if (event.originalTarget.nodeName == 'BODY' || event.originalTarget.nodeName == 'HTML') {
$('#timeline').data('down', false);
}
} catch (e) {}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment