Skip to content

Instantly share code, notes, and snippets.

@companje
Last active August 15, 2019 08:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save companje/c28b2b192744a369d38fca2946ac1af2 to your computer and use it in GitHub Desktop.
Save companje/c28b2b192744a369d38fca2946ac1af2 to your computer and use it in GitHub Desktop.
Javascript contactsheet / spritesheet / thumbsheet / video thumb scrub
/*
CSS:
.thumb {
width: 192px;
height: 146px;
border: 1px solid black;
background-image: url(140001.jpg); //140001.jpg is a thumbsheet of 10x10
}
*/
function onmousemove(event) {
const pct = event.offsetX / event.target.offsetWidth;
const rows = 10;
const cols = 10;
const index = pct * rows * cols;
const sheetWidth = 1950;
const sheetHeight = 1460;
const x = (Math.ceil(index % cols) / cols) * sheetWidth;
const y = (Math.ceil(index / rows) / rows) * sheetHeight;
div.style.backgroundPosition = `${x}px ${y}px`;
}
//setup
div.onmousemove = onmousemove;
@companje
Copy link
Author

140001

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