Created
July 8, 2016 07:09
-
-
Save arangates/8ecc508e1a071a1b1a6977d8a71dcc6e to your computer and use it in GitHub Desktop.
GSAP Image Tilt Effect on Hover with Image Layers
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
<div class="above-fold"> | |
<div class="hero-section" id="hero-section-a"> | |
<img src="http://videosmith.wpengine.com/wp-content/uploads/2016/06/tyler-movi.jpg" /></div> | |
<div class="hero-section" id="hero-section-b"> | |
<img src="http://videosmith.wpengine.com/wp-content/uploads/2016/06/tyler-movi.jpg" /></div> | |
<div class="hero-section" id="hero-section-c"> | |
<img src="http://videosmith.wpengine.com/wp-content/uploads/2016/06/tyler-movi.jpg" /></div> | |
</div> |
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
jQuery(function( $ ){ | |
var $body=$("body"), | |
$heroA=$("#hero-section-a img"), | |
$heroB=$("#hero-section-b img"), | |
$heroC=$("#hero-section-c img"); | |
TweenMax.set( $heroA, { transformStyle: 'preserve-3d' }); | |
TweenMax.set( $heroB, { transformStyle: 'preserve-3d' }); | |
TweenMax.set( $heroC, { transformStyle: 'preserve-3d' }); | |
$body.mousemove(function(e) { | |
var sxPos = e.pageX / $body.width() * 100 - 50; | |
var syPos = e.pageY / $body.height() * 100 - 50; | |
console.log("x:" + sxPos + ", y:" + syPos); | |
TweenMax.to( $heroA, 1, { rotationY: 0.05 * sxPos, rotationX: 0.20 * syPos, rotationZ: '-0.1', transformPerspective:500, transformOrigin:'center center' }); | |
TweenMax.to( $heroB, 1, { rotationY: 0.10 * sxPos, rotationX: 0.15 * syPos, rotationZ: 0, transformPerspective:500, transformOrigin:'center center' }); | |
TweenMax.to( $heroC, 1, { rotationY: 0.15 * sxPos, rotationX: 0.10 * syPos, rotationZ: 0.10, transformPerspective:500, transformOrigin:'center center' }); | |
}); | |
}); |
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
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0/jquery.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/1.18.5/TweenMax.min.js"></script> |
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
body { | |
width: 100%; | |
background-image: radial-gradient(circle farthest-side at center bottom, crimson, #003087 130%); | |
overflow: hidden; | |
} | |
div { | |
box-sizing: border-box; | |
display: block; | |
} | |
.above-fold { | |
position: relative; | |
height: 100vh; | |
overflow: hidden; | |
width: 100%; | |
} | |
.hero-section { | |
filter: grayscale(100%); | |
-webkit-filter: grayscale(100%); | |
z-index: -1; | |
} | |
.hero-section img { | |
position: absolute; | |
opacity: 0.45; | |
margin: auto; | |
width: 150%; | |
top: -25%; | |
right: -25%; | |
bottom: -25%; | |
left: -25%; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment