<script src="https://rawgithub.com/janpaepke/ScrollMagic/master/js/jquery.scrollmagic.min.js"></script>
<header role="banner">
<img src="//s3-us-west-2.amazonaws.com/s.cdpn.io/392/demo_tophat.png" width="64" height="auto" alt="scroll magic">
</header>
<main class="full-screen" role="main">
<section class="full-screen blue">
<div>
<h1>Basic Pin</h1>
<p>Elements are pinned for their respective pixel value set as the duration and released again.</p>
</div>
</section>
<section id="pinned-trigger1" class="full-screen orange">
<div id="pinned-element1">
<p>This element will be pinned once it's trigger hits the top of the viewport and will have a duration of window height minus 100</p>
</div>
</section>
<section id="pinned-trigger2" class="full-screen red">
<div id="pinned-element2">
<p>This element will be pinned for a duration of 150px</p>
</div>
</section>
<section id="pinned-trigger3" class="full-screen orange">
<div id="pinned-element3">
<p>elemnto 3</p>
</div>
</section>
<section class="full-screen blue">
<div>
<p>Section Four!</p>
</div>
</section>
</main>
// init ScrollMagic Controller
controller = new ScrollMagic();
// Scene Handler
var scene = new ScrollScene({
triggerElement: "#pinned-trigger1", // point of execution
duration: $(window).height() - 100, // pin element for the window height - 1
triggerHook: 0, // don't trigger until #pinned-trigger1 hits the top of the viewport
reverse: true // allows the effect to trigger when scrolled in the reverse direction
})
.setPin("#pinned-element1"); // the element we want to pin
// Scene2 Handler
var scene2 = new ScrollScene({
triggerElement: "#pinned-trigger2", // point of execution
duration: 150 // pin the element for a total of 400px
})
.setPin("#pinned-element2"); // the element we want to pin
// Scene3 Handler
var scene3 = new ScrollScene({
triggerElement: "#pinned-trigger3", // point of execution
duration: 100 // pin the element for a total of 400px
})
.setPin("#pinned-element3"); // the element we want to pin
// Add Scenes to ScrollMagic Controller
controller.addScene([
scene,
scene2,
scene3
]);
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.