Skip to content

Instantly share code, notes, and snippets.

@csessig86
Last active December 14, 2015 02:58
Show Gist options
  • Save csessig86/5017273 to your computer and use it in GitHub Desktop.
Save csessig86/5017273 to your computer and use it in GitHub Desktop.
Before, after photos: Javascript
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
<script type="text/javascript" language="JavaScript">
$(document).ready(function() {
$('.trackMe').each(function(){
$(this).children("img:last").mousemove(function(e) {
var offset = $(this).offset();
var xpos = (e.pageX - offset.left);
var ypos = (e.pageY - offset.top);
//now to get the first child image width..
var thisImage = $(this);
var thisWidth = thisImage.width();
var pct = Math.round((xpos/thisWidth)*100)/100;
var ipct = Math.abs(Math.round(((xpos-thisWidth)/thisWidth)*100)/100);
thisImage.css({ 'opacity' : ipct });
});
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment