Created
July 21, 2011 03:03
-
-
Save laughinghan/1096417 to your computer and use it in GitHub Desktop.
Minimap of a web page
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
javascript: | |
var minimap = document.body.cloneNode(true); | |
[].forEach.call(minimap.getElementsByTagName('a'), function(link) { | |
link.href = 'javascript:;'; | |
}); | |
minimap.style.position = 'fixed'; | |
minimap.style.webkitTransform = 'scale(.1)'; | |
document.body.appendChild(minimap); | |
minimap.style.top = minimap.offsetHeight*-.45+'px'; | |
minimap.style.right = minimap.offsetWidth*-.45+'px'; | |
minimap.onmousedown = function(e) { | |
document.body.scrollTop = 10*e.clientY-innerHeight/2; | |
document.onmousemove = arguments.callee; | |
document.onmouseup = function(){ document.onmousemove = null; }; | |
return false; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can you explain this line:
document.body.scrollTop = 10*e.clientY-innerHeight/2;
Why
10 * e.clientY - innerHeight / 2
? A precise value or estimate?