A Pen by designcourse on CodePen.
Created
April 18, 2020 17:02
-
-
Save samlovescoding/4013ac31c412813ec4ad04a75aa7c260 to your computer and use it in GitHub Desktop.
UI Animating on Scroll: GSAP + ScrollMagic
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
<section> | |
<h1>Scroll down</h1> | |
</section> | |
<section class="sticky"> | |
<blockquote>"You should totally subscribe to my channel now"<span></span></blockquote> | |
<img id="office" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/2621168/office1.png"> | |
<img id="building" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/2621168/sky.jpg"> | |
<div id="box"></div> | |
</section> | |
<section> | |
<h1>Scroll up</h1> | |
</section> |
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
var tl = new TimelineMax({onUpdate:updatePercentage}); | |
var tl2 = new TimelineMax(); | |
const controller = new ScrollMagic.Controller(); | |
tl.from('blockquote', .5, {x:200, opacity: 0}); | |
tl.from('span', 1, { width: 0}, "=-.5"); | |
tl.from('#office', 1, {x:-200, opacity: 0,ease: Power4.easeInOut}, "=-1"); | |
tl.from('#building', 1, {x:200, opacity: 0, ease: Power4.easeInOut}, "=-.7"); | |
tl2.from("#box", 1, {opacity: 0, scale: 0}); | |
tl2.to("#box", .5, {left: "20%", scale: 1.3, borderColor: 'white', borderWidth: 12, boxShadow: '1px 1px 0px 0px rgba(0,0,0,0.09)'}) | |
const scene = new ScrollMagic.Scene({ | |
triggerElement: ".sticky", | |
triggerHook: "onLeave", | |
duration: "100%" | |
}) | |
.setPin(".sticky") | |
.setTween(tl) | |
.addTo(controller); | |
const scene2 = new ScrollMagic.Scene({ | |
triggerElement: "blockquote" | |
}) | |
.setTween(tl2) | |
.addTo(controller); | |
function updatePercentage() { | |
//percent.innerHTML = (tl.progress() *100 ).toFixed(); | |
tl.progress(); | |
console.log(tl.progress()); | |
} |
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/gsap/2.0.2/TweenMax.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/2.0.2/TimelineMax.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/ScrollMagic/2.0.6/ScrollMagic.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/ScrollMagic/2.0.6/plugins/animation.gsap.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
@import url('https://fonts.googleapis.com/css?family=Arapey'); | |
body { | |
margin: 0; | |
font-family: 'Arapey'; | |
h1 { | |
font-size: 2em; | |
text-align: center; | |
margin-top: 30%; | |
} | |
} | |
section { | |
padding: 3em; | |
height: 100vh; | |
position: relative; | |
box-sizing: border-box; | |
blockquote { | |
font-size: 2.3em; | |
width: 30%; | |
margin-top: 17%; | |
position: absolute; | |
span { | |
width: 100%; | |
background: red; | |
display: block; | |
height: 5px; | |
margin-top: 20px; | |
} | |
} | |
img { | |
position: absolute; | |
} | |
img:nth-of-type(1) { | |
width: 40%; | |
right: 0; | |
top: 20%; | |
} | |
img:nth-of-type(2) { | |
width: 25%; | |
right: 40%; | |
top: 29%; | |
margin-top: 15%; | |
} | |
} | |
section:nth-child(odd) { | |
background: #f1f1f1; | |
} | |
.sticky { | |
background: white !important; | |
} | |
.percentage { | |
position: absolute; | |
bottom: 10px; | |
left: 10px; | |
} | |
#box { | |
width: 100px; | |
height: 100px; | |
position: absolute; | |
border: 5px solid lightgray; | |
margin: auto; | |
top: 0; left: 0; bottom: 0; right: 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment