Skip to content

Instantly share code, notes, and snippets.

@laughinghan
Created July 21, 2011 03:03
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save laughinghan/1096417 to your computer and use it in GitHub Desktop.
Save laughinghan/1096417 to your computer and use it in GitHub Desktop.
Minimap of a web page
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;
};
@lyyourc
Copy link

lyyourc commented Apr 11, 2016

Can you explain this line: document.body.scrollTop = 10*e.clientY-innerHeight/2;

Why 10 * e.clientY - innerHeight / 2? A precise value or estimate?

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