Skip to content

Instantly share code, notes, and snippets.

@yuryshulaev
Last active May 11, 2020 04:42
Show Gist options
  • Save yuryshulaev/fce36d11a1a1adc04d49 to your computer and use it in GitHub Desktop.
Save yuryshulaev/fce36d11a1a1adc04d49 to your computer and use it in GitHub Desktop.
Greasemonkey drag-style scrolling userscript
// ==UserScript==
// @name DragScroll
// @include *
// @version 1
// @grant none
// @require http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js
// ==/UserScript==
(function ($) {
var dragging = false;
var initialLeft, initialTop, initialX, initialY;
var scrollable = $(window);
var button = 3;
scrollable.contextmenu(function (e) {
return false;
});
scrollable.mousedown(function (e) {
if (e.which !== button) {
return true;
}
dragging = true;
initialLeft = $(this).scrollLeft();
initialTop = $(this).scrollTop();
initialX = e.clientX;
initialY = e.clientY;
return false;
});
scrollable.mousemove(function (e) {
if (dragging) {
$(this).scrollLeft(initialLeft - (e.clientX - initialX));
$(this).scrollTop(initialTop - (e.clientY - initialY));
return false;
}
});
scrollable.mouseup(function (e) {
if (e.which !== button) {
return true;
}
dragging = false;
return false;
});
})(jQuery.noConflict(true));
@yuryshulaev
Copy link
Author

yuryshulaev commented May 9, 2020

I have also used this addon: https://addons.mozilla.org/ru/firefox/addon/scroll_anywhere/ — it has a lot of settings.

@Noomene
Copy link

Noomene commented May 10, 2020

Thanks a lot mate. This || e.ctrlKey is what I was looking for.

However, I was already using that scroll anywhere add on on waterfox, but since I switched to pale moon, it didn't work there and greasemonkey seemed like the only solution. But then someone directed to an old repo of old firefox addons and I found a good alternative to it for pale moon.

Thanks a lot again for your reply mate, I appreciate your help and this little gem of script.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment