<div class="animatable-element supersonic-element">
I'm an animatable element, start scrolling to see me animating<br />
Once I will be played to the end I will stop rendering
</div>
<div class="animatable-element-2 supersonic-element">
I'm an animatable element, start scrolling to see me animating<br />
I am rendering as usual
</div>
<div class="start supersonic-driver">
I'm a driver, I start an animation when I appear
</div>
<div class="end supersonic-driver">
I'm a driver, I finish an animation when I appear
</div>
.start {
position: absolute;
top: 100vh;
}
.end {
position: absolute;
top: 200vh;
}
.animatable-element,
.animatable-element-2 {
position: fixed;
left: 18px;
top: 50%;
z-index: 10;
animation-name: animation;
animation-duration: 10s; /* This is required */
animation-play-state: paused; /* This is required, playback is controlled by plugin */
animation-timing-function: linear; /* This is recommended so that your animation will be consistent */
animation-fill-mode: forwards; /* This is recommended so that your animation holds last frame on finish */
}
.animatable-element-2 {
left: auto;
right: 18px;
}
@keyframes animation {
to {
scale: 1.5;
}
}
import { TheSupersonicPlugin } from "https://esm.sh/the-supersonic-plugin-for-scroll-based-animation@2.1.0";
new TheSupersonicPlugin([
{
// This made for educational purpose. If you have 1 driver controlling multiple animations and you want to control one of them, it's better to use animation hooks, see next example
start: ".start",
end: ".end",
elements: [".animatable-element"],
hooks: {
onBeforeInit(driver) {
driver.data.isRendering = true; // It's not a part of library, it's a custom variable, you can create any
},
onBeforeRender(driver) {
if (driver.progress === 1) driver.data.isRendering = false;
return driver.data.isRendering; // Returning false prevents driver from rendering
}
}
},
{
start: ".start",
end: ".end",
elements: [".animatable-element-2"]
}
]);
This Pen doesn't use any external JavaScript resources.