Skip to content

Installation

Terminal window
npm install motion-on-scroll

You’ll need to import MOS styles, and run the MOS.init() function.

<!-- Import MOS styles -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/motion-on-scroll@latest/dist/mos.css" />
<!-- Initialize MOS -->
<script type="module">
import { MOS } from 'motion-on-scroll';
MOS.init();
</script>
<!-- Somewhere in your markup -->
<section data-mos="fade-up">
...
</section>

That’s it! Every element declaring a data-mos value is now animated when it enters the viewport.

MOS ships with a small stylesheet that ensures elements are hidden upon initial page load. Import it from motion-on-scroll/dist/mos.css or copy the file into your own pipeline. The contents of the file are below for convenience.

/* no pointer events until animation starts */
[data-mos] {
pointer-events: none;
}
[data-mos].mos-animate {
pointer-events: auto;
}
/* fade & zoom presets */
[data-mos^="fade"],
[data-mos^="zoom"] {
will-change: opacity, transform;
opacity: 0;
}
/* slide presets */
[data-mos^="slide"] {
will-change: transform;
}
/* flip presets */
[data-mos^="flip"] {
will-change: transform;
transform: rotateY(-180deg);
backface-visibility: hidden;
}