Skip to content

Instantly share code, notes, and snippets.

@KaiserEMP
Created March 6, 2019 08:20
Show Gist options
  • Save KaiserEMP/1fa81b50cf5efabfff26b068a2a34378 to your computer and use it in GitHub Desktop.
Save KaiserEMP/1fa81b50cf5efabfff26b068a2a34378 to your computer and use it in GitHub Desktop.
Click and Drag SCroll
/* 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