Skip to content

Instantly share code, notes, and snippets.

@benfarahmand
Last active December 11, 2015 14:08
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 benfarahmand/4612183 to your computer and use it in GitHub Desktop.
Save benfarahmand/4612183 to your computer and use it in GitHub Desktop.
JQuery Image Grid. Example of working code is here: http://www.ragtimelolcat.com/
var imageWidth = 800;
var imageHeight = 450;
var gridWidth = imageWidth/10;
var gridHeight = imageHeight/10;
var halfGWidth = gridWidth/2;
var halfGHeight = gridHeight/2;
$(document).mousemove(function(e){
if(e.pageX for(var i = 0; i <= imageWidth ; i = i+gridWidth){
for(var j = 0; j <= imageHeight ; j = j +gridHeight){
if(Math.abs(e.pageX-(i-halfGWidth)) var tempY = new String(""+(j-gridHeight)/gridHeight);
var tempX = new String(""+(i-gridWidth)/gridWidth);
document.getElementById("image").src="image"+parseInt(tempY+tempX)+".jpg";
}
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment