A Pen by Alexandros K on CodePen.
Created
April 30, 2020 17:03
-
-
Save artsyca/a934d6651b64bbfc28997c9390e93ed6 to your computer and use it in GitHub Desktop.
mdeBdVN
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
<h1>I change colour</h1> | |
<div id="trigger">This is the trigger, scroll it in and out of the view</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
console.clear(); | |
const trigger = $("#trigger"); | |
const target = $("h1"); | |
const tl = gsap.timeline(); | |
const controller = new ScrollMagic.Controller(); | |
const scene = new ScrollMagic.Scene({ | |
triggerElement: $("#trigger")[0], | |
triggerHook: 'onLeave', | |
reverse: true, | |
tweenChanges: false, | |
duration: 10 // duration 0 or longer behaves the same | |
}); | |
// works | |
// requires a slight offset | |
tl.call(myFunc, [target], '0.0001'); | |
// doesn't work, only triggers once | |
// tl.call(myFunc, [target]); | |
// not sure if this works as expcted or what the expected behaviour would be | |
// tl.to(trigger, { | |
// background: 'black' | |
// }).call(myFunc, [target], '<') | |
// but this works better now | |
// tl.to(trigger, { | |
// background: 'black' | |
// }).call(myFunc, [target]) | |
scene.setTween(tl); | |
controller.addScene(scene); | |
var counter = 0; | |
function myFunc(target) { | |
console.log(`called ${counter++}`) | |
target.toggleClass("active"); | |
} | |
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=Signika+Negative:300,400&display=swap'); | |
body { | |
font-family: "Signika Negative", sans-serif; | |
font-weight: 300; | |
} | |
h1 { | |
position: fixed; | |
} | |
h1.active { | |
color: cyan; | |
} | |
#trigger { | |
height: 2000px; | |
width: 500px; | |
background: magenta; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment