Last active
December 14, 2015 02:58
-
-
Save csessig86/5017273 to your computer and use it in GitHub Desktop.
Before, after photos: Javascript
This file contains hidden or 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
<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