-
-
Save KaiserEMP/1fa81b50cf5efabfff26b068a2a34378 to your computer and use it in GitHub Desktop.
Click and Drag SCroll
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
/* click and drag */ | |
$.fn.attachDragger = function () { | |
var attachment = false, lastPosition, position, difference; | |
$($(this).selector).on("mousedown mouseup mousemove", function (e) { | |
if (e.type == "mousedown") attachment = true, lastPosition = [e.clientX, e.clientY]; // jshint ignore:line | |
if (e.type == "mouseup") attachment = false; | |
if (e.type == "mousemove" && attachment == true) { | |
position = [e.clientX, e.clientY]; | |
difference = [(position[0] - lastPosition[0]), (position[1] - lastPosition[1])]; | |
$(this).scrollLeft($(this).scrollLeft() - difference[0]); | |
$(this).scrollTop($(this).scrollTop() - difference[1]); | |
lastPosition = [e.clientX, e.clientY]; | |
} | |
}); | |
$(window).on("mouseup", function () { | |
attachment = false; | |
}); | |
}; | |
$(".timeline-container").attachDragger(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment