Last active
August 15, 2019 08:14
-
-
Save companje/c28b2b192744a369d38fca2946ac1af2 to your computer and use it in GitHub Desktop.
Javascript contactsheet / spritesheet / thumbsheet / video thumb scrub
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
/* | |
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; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Processing code for testing: