Last active
May 11, 2020 04:42
-
-
Save yuryshulaev/fce36d11a1a1adc04d49 to your computer and use it in GitHub Desktop.
Greasemonkey drag-style scrolling userscript
This file contains 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
// ==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)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.