-
-
Save diogenesjup/f45adf670c87b18368dd6970392bc934 to your computer and use it in GitHub Desktop.
jQuery: Drag and scroll horizontal div
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="text/javascript"> | |
$(document).ready(function() { | |
$('.dragger').mousedown(function (event) { | |
$(this) | |
.data('down', true) | |
.data('x', event.clientX) | |
.data('scrollLeft', this.scrollLeft) | |
.addClass("dragging"); | |
return false; | |
}).mouseup(function (event) { | |
$(this) | |
.data('down', false) | |
.removeClass("dragging"); | |
}).mousemove(function (event) { | |
if ($(this).data('down') == true) { | |
this.scrollLeft = $(this).data('scrollLeft') + $(this).data('x') - event.clientX; | |
} | |
}).mousewheel(function (event, delta) { | |
this.scrollLeft -= (delta * 30); | |
}).css({ | |
'overflow' : 'hidden', | |
'cursor' : '-moz-grab' | |
}); | |
$(window).mouseout(function (event) { | |
if ($('.team-form-data').data('down')) { | |
try { | |
if (event.originalTarget.nodeName == 'BODY' || event.originalTarget.nodeName == 'HTML') { | |
$('.team-form-data').data('down', false); | |
} | |
} catch (e) {} | |
} | |
}); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment