{"id":4899,"date":"2021-11-10T01:00:00","date_gmt":"2021-11-10T00:00:00","guid":{"rendered":"https:\/\/alvarotrigo.com\/epa\/css-animations-scroll\/"},"modified":"2024-07-16T20:04:53","modified_gmt":"2024-07-16T18:04:53","slug":"css-animations-scroll","status":"publish","type":"post","link":"https:\/\/alvarotrigo.com\/blog\/css-animations-scroll\/","title":{"rendered":"How to Create CSS Animations on Scroll [With Examples]"},"content":{"rendered":"\n<p><strong>CSS Scroll animations<\/strong> are a great way to bring boring and static sites to life and give the reader a more interesting, unique, and modern experience.<\/p>\n\n\n\n<p>In this post, you will learn <strong>how to trigger CSS animations on scroll.<\/strong><\/p>\n\n\n\n<p>And&#8230; who knows? Maybe you will end up creating unique websites like <a href=\"https:\/\/alvarotrigo.com\/blog\/scrolling-animation\/\">these scroll-animated websites<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"what-are-css-scroll-animations%3F\">What are CSS Scroll Animations?<\/h2>\n\n\n\n<p><strong>CSS scroll animations are animations that get triggered using CSS when the user scrolls through a website.<\/strong> Usually, the scroll-driven animation is triggered when the element comes into view, and it can be applied to practically any element, such as text, images, and videos.<\/p>\n\n\n\n<p>Our eyes are naturally attracted to movement so this feature will entice and keep the visitor engaged. Adding <a href=\"https:\/\/alvarotrigo.com\/blog\/10-cool-css-animations-to-add-to-your-website\/\">eye-catching animations<\/a> to your website will make it stand out from the rest, and when used properly, scroll animations can add a modern touch to a website.<\/p>\n\n\n\n<p>Any <strong>CSS Scroll animation<\/strong> usually involves using a plugin or library, but we will show you how to achieve this without those. And we will do it in two ways, one using new experimental CSS features and in the traditional way that involves using plain JavaScript.<\/p>\n\n\n\n<p>So, let\u2019s get to it.<\/p>\n\n\n\n<h2 id=\"scrollbased-animations-with-pure-css\" class=\"wp-block-heading\">Scroll-based Animations with Pure CSS<\/h2>\n\n\n\n<p>Traditionally, <strong>scroll-driven animations<\/strong> using only CSS were not possible. However, there are now new CSS experimental properties that allow us to do so.<\/p>\n\n\n\n<p>If you prefer not to rely on external libraries or JavaScript, you can still trigger <strong>CSS-based animations on scroll<\/strong> by using the CSS property <code><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/animation-timeline\" rel=\"nofollow noopener\" target=\"_blank\">animation-timeline<\/a><\/code>&nbsp;and the <code><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/animation-timeline\/scroll\" rel=\"nofollow noopener\" target=\"_blank\">scroll()<\/a><\/code> function as its value. <\/p>\n\n\n\n<div class=\"wp-block-cp-codepen-gutenberg-embed-block cp_embed_wrapper\"><iframe id=\"cp_embed_wvLKRPE\" data-src=\"\/\/codepen.io\/anon\/embed\/wvLKRPE?height=450&amp;theme-id=1&amp;slug-hash=wvLKRPE&amp;default-tab=result\" height=\"450\" scrolling=\"no\" frameborder=\"0\" allowfullscreen allowpaymentrequest name=\"CodePen Embed wvLKRPE\" title=\"CodePen Embed wvLKRPE\" class=\"cp_embed_iframe lazyload\" style=\"width:100%;overflow:hidden\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" data-load-mode=\"1\">CodePen Embed Fallback<\/iframe><\/div>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>Note the CSS feature <a href=\"https:\/\/caniuse.com\/mdn-css_properties_animation-timeline_scroll\" rel=\"nofollow noopener\" target=\"_blank\">&#8220;animation-timeline: scroll()&#8221; is still not fully supported<\/a> by all web browsers like Safari or Firefox<strong>.<\/strong> If you need to provide support for all browsers I recommend using <a href=\"https:\/\/github.com\/flackr\/scroll-timeline\" rel=\"nofollow noopener\" target=\"_blank\">this polyfill<\/a>.<\/p>\n<\/blockquote>\n\n\n\n<p>Let&#8217;s create a simple example where we will show a scroll indicator at the top of the page. This indicator will become bigger in size the more we scroll until reaching the bottom.<\/p>\n\n\n\n<h3 id=\"1-create-the-html-markup\" class=\"wp-block-heading\">1. Create the HTML Markup<\/h3>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"HTML, XML\" data-shcb-language-slug=\"xml\"><span><code class=\"hljs language-xml\"><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">div<\/span> <span class=\"hljs-attr\">class<\/span>=<span class=\"hljs-string\">\"scroll-watcher\"<\/span>&gt;<\/span><span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">div<\/span>&gt;<\/span>\n\n<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">div<\/span> <span class=\"hljs-attr\">class<\/span>=<span class=\"hljs-string\">\"box\"<\/span>&gt;<\/span>Scroll<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">div<\/span>&gt;<\/span>\n<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">div<\/span> <span class=\"hljs-attr\">class<\/span>=<span class=\"hljs-string\">\"box\"<\/span>&gt;<\/span>Scroll<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">div<\/span>&gt;<\/span>\n<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">div<\/span> <span class=\"hljs-attr\">class<\/span>=<span class=\"hljs-string\">\"box\"<\/span>&gt;<\/span>Scroll<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">div<\/span>&gt;<\/span>\n<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">div<\/span> <span class=\"hljs-attr\">class<\/span>=<span class=\"hljs-string\">\"box\"<\/span>&gt;<\/span>Scroll<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">div<\/span>&gt;<\/span>\n<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">div<\/span> <span class=\"hljs-attr\">class<\/span>=<span class=\"hljs-string\">\"box\"<\/span>&gt;<\/span>Scroll<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">div<\/span>&gt;<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">HTML, XML<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">xml<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>We create the <code>scroll-watcher<\/code> element that will <strong>animate on scroll<\/strong>. Then, to make the page scrollable, we added some &#8220;dummy&#8221; elements with the class <code>box<\/code> .<\/p>\n\n\n\n<h3 id=\"2-styling-the-elements\" class=\"wp-block-heading\">2. Styling the Elements<\/h3>\n\n\n\n<p>We will be adding our scroll indicator on the very top as a horizontal line that increases in width while we scroll down. Then, the dummy boxes force the page to be scrollable. <\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\"><span class=\"hljs-selector-class\">.scroll-watcher<\/span> {\n  <span class=\"hljs-attribute\">height<\/span>: <span class=\"hljs-number\">10px<\/span>;\n  <span class=\"hljs-attribute\">position<\/span>: fixed;\n  <span class=\"hljs-attribute\">top<\/span>: <span class=\"hljs-number\">0<\/span>;\n  <span class=\"hljs-attribute\">left<\/span>:<span class=\"hljs-number\">0<\/span>;\n  <span class=\"hljs-attribute\">z-index<\/span>: <span class=\"hljs-number\">1000<\/span>;\n  <span class=\"hljs-attribute\">background-color<\/span>: red;\n  <span class=\"hljs-attribute\">width<\/span>: <span class=\"hljs-number\">100%<\/span>;\n}\n\n<span class=\"hljs-selector-class\">.box<\/span> {\n  <span class=\"hljs-attribute\">height<\/span>: <span class=\"hljs-number\">60vh<\/span>;\n  <span class=\"hljs-attribute\">padding<\/span>: <span class=\"hljs-number\">30px<\/span> <span class=\"hljs-number\">0<\/span> <span class=\"hljs-number\">0<\/span> <span class=\"hljs-number\">0<\/span>;\n  <span class=\"hljs-attribute\">text-align<\/span>: center;\n  <span class=\"hljs-attribute\">background<\/span>: <span class=\"hljs-number\">#4e4e4e<\/span>;\n  <span class=\"hljs-attribute\">width<\/span>: <span class=\"hljs-number\">400px<\/span>;\n  <span class=\"hljs-attribute\">margin<\/span>: <span class=\"hljs-number\">30px<\/span> auto;\n  <span class=\"hljs-attribute\">border-radius<\/span>: <span class=\"hljs-number\">12px<\/span>;\n  <span class=\"hljs-attribute\">font-size<\/span>: <span class=\"hljs-number\">1.4em<\/span>;\n  <span class=\"hljs-attribute\">color<\/span>: white;\n}\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h3 id=\"3-creating-the-animation-on-scroll\" class=\"wp-block-heading\">3. Creating the Animation on Scroll<\/h3>\n\n\n\n<p>Now, we will add the magic that will allow us to trigger animations on scroll. We will be adding these styles to the <code>.scroll-watcher<\/code>&nbsp;element:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\">  <span class=\"hljs-comment\">\/* Initial X scale will be 0, Y will be 1*\/<\/span>\n  <span class=\"hljs-selector-tag\">scale<\/span>: 0 1;\n\n  <span class=\"hljs-selector-tag\">transform-origin<\/span>: <span class=\"hljs-selector-tag\">left<\/span>;\n  \n  <span class=\"hljs-comment\">\/* Defining the animation and its easing function *\/<\/span>\n  <span class=\"hljs-selector-tag\">animation<\/span>: <span class=\"hljs-selector-tag\">scroll-watcher<\/span> <span class=\"hljs-selector-tag\">linear<\/span>;\n\n  <span class=\"hljs-comment\">\/* Adding the scroll trigger *\/<\/span>\n  <span class=\"hljs-selector-tag\">animation-timeline<\/span>: <span class=\"hljs-selector-tag\">scroll<\/span>(<span class=\"hljs-selector-tag\">y<\/span>);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>And the <code>scroll-wather<\/code> animation that will define how we want the element to animate; in this case, the element will scale the X property to its maximum value once the scroll reaches the end:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\"><span class=\"hljs-keyword\">@keyframes<\/span> scroll-watcher {\n  <span class=\"hljs-selector-tag\">to<\/span> {\n    <span class=\"hljs-attribute\">scale<\/span>: <span class=\"hljs-number\">1<\/span> <span class=\"hljs-number\">1<\/span>;\n  }\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h3 id=\"4-heres-our-final-css\" class=\"wp-block-heading\">4. Here&#8217;s our final CSS<\/h3>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\"><span class=\"hljs-selector-class\">.scroll-watcher<\/span> {\n  <span class=\"hljs-attribute\">height<\/span>: <span class=\"hljs-number\">10px<\/span>;\n  <span class=\"hljs-attribute\">position<\/span>: fixed;\n  <span class=\"hljs-attribute\">top<\/span>: <span class=\"hljs-number\">0<\/span>;\n  <span class=\"hljs-attribute\">left<\/span>:<span class=\"hljs-number\">0<\/span>;\n  <span class=\"hljs-attribute\">z-index<\/span>: <span class=\"hljs-number\">1000<\/span>;\n  <span class=\"hljs-attribute\">background-color<\/span>: red;\n  <span class=\"hljs-attribute\">width<\/span>: <span class=\"hljs-number\">100%<\/span>;\n  <span class=\"hljs-attribute\">scale<\/span>: <span class=\"hljs-number\">0<\/span> <span class=\"hljs-number\">1<\/span>;\n  <span class=\"hljs-attribute\">transform-origin<\/span>: left;\n  <span class=\"hljs-attribute\">animation<\/span>: scroll-watcher linear;\n  <span class=\"hljs-attribute\">animation-timeline<\/span>: <span class=\"hljs-built_in\">scroll<\/span>(y);\n}\n\n<span class=\"hljs-keyword\">@keyframes<\/span> scroll-watcher {\n  <span class=\"hljs-selector-tag\">to<\/span> {\n    <span class=\"hljs-attribute\">scale<\/span>: <span class=\"hljs-number\">1<\/span> <span class=\"hljs-number\">1<\/span>;\n  }\n}\n\n<span class=\"hljs-selector-class\">.box<\/span> {\n  <span class=\"hljs-attribute\">height<\/span>: <span class=\"hljs-number\">60vh<\/span>;\n  <span class=\"hljs-attribute\">padding<\/span>: <span class=\"hljs-number\">30px<\/span> <span class=\"hljs-number\">0<\/span> <span class=\"hljs-number\">0<\/span> <span class=\"hljs-number\">0<\/span>;\n  <span class=\"hljs-attribute\">text-align<\/span>: center;\n  <span class=\"hljs-attribute\">background<\/span>: <span class=\"hljs-number\">#4e4e4e<\/span>;\n  <span class=\"hljs-attribute\">width<\/span>: <span class=\"hljs-number\">400px<\/span>;\n  <span class=\"hljs-attribute\">margin<\/span>: <span class=\"hljs-number\">30px<\/span> auto;\n  <span class=\"hljs-attribute\">border-radius<\/span>: <span class=\"hljs-number\">12px<\/span>;\n  <span class=\"hljs-attribute\">font-size<\/span>: <span class=\"hljs-number\">1.4em<\/span>;\n  <span class=\"hljs-attribute\">color<\/span>: white;\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 id=\"trigger-inview-css-animations-on-scroll\" class=\"wp-block-heading\">Trigger In-view CSS Animations On Scroll<\/h2>\n\n\n\n<div class=\"wp-block-cp-codepen-gutenberg-embed-block cp_embed_wrapper\"><iframe id=\"cp_embed_vYqNbgV\" data-src=\"\/\/codepen.io\/anon\/embed\/vYqNbgV?height=450&amp;theme-id=1&amp;slug-hash=vYqNbgV&amp;default-tab=result\" height=\"450\" scrolling=\"no\" frameborder=\"0\" allowfullscreen allowpaymentrequest name=\"CodePen Embed vYqNbgV\" title=\"CodePen Embed vYqNbgV\" class=\"cp_embed_iframe lazyload\" style=\"width:100%;overflow:hidden\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" data-load-mode=\"1\">CodePen Embed Fallback<\/iframe><\/div>\n\n\n\n<p>What if you want to trigger an animation when the element enters the viewport instead of based on the scroll position?<\/p>\n\n\n\n<p>This can also be done using the same <code><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/animation-timeline\" rel=\"nofollow noopener\" target=\"_blank\">animation-timeline<\/a><\/code>&nbsp;property but in this case using the function <code><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/animation-timeline\/view\" rel=\"nofollow noopener\" target=\"_blank\">view()<\/a><\/code>&nbsp;as its value.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>Note the CSS feature <a href=\"https:\/\/caniuse.com\/mdn-css_properties_animation-timeline_scroll\" rel=\"nofollow noopener\" target=\"_blank\">&#8220;animation-timeline: scroll()&#8221; is still not fully supported<\/a> by all web browsers like Safari or Firefox<strong>.<\/strong> If you need to provide support for all browsers I recommend using <a href=\"https:\/\/github.com\/flackr\/scroll-timeline\" rel=\"nofollow noopener\" target=\"_blank\">this polyfill<\/a>.<\/p>\n<\/blockquote>\n\n\n\n<p>It&#8217;s quite common to see websites showing text elements fading in or slightly animating into the viewport when scrolling the page. Traditionally, this was done using JavaScript, but now we can replicate some of those effects using just CSS.<\/p>\n\n\n\n<p>Let&#8217;s create a simple example where we are fading images once they enter into view.<\/p>\n\n\n\n<h3 id=\"1-setting-up-the-html\" class=\"wp-block-heading\">1. Setting up the HTML<\/h3>\n\n\n\n<p>We will be adding some elements to make the page scrollable like before, then the images in  between:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"HTML, XML\" data-shcb-language-slug=\"xml\"><span><code class=\"hljs language-xml\"><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">div<\/span> <span class=\"hljs-attr\">class<\/span>=<span class=\"hljs-string\">\"box\"<\/span>&gt;<\/span>Scroll<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">div<\/span>&gt;<\/span>\n...\n<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">img<\/span> <span class=\"hljs-attr\">src<\/span>=<span class=\"hljs-string\">\"https:\/\/example.com\/image.jpg\"<\/span> \/&gt;<\/span>\n<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">div<\/span> <span class=\"hljs-attr\">class<\/span>=<span class=\"hljs-string\">\"box\"<\/span>&gt;<\/span>Scroll<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">div<\/span>&gt;<\/span>\n...\n<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">img<\/span> <span class=\"hljs-attr\">src<\/span>=<span class=\"hljs-string\">\"https:\/\/example.com\/image.jpg\"<\/span> \/&gt;<\/span>\n<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">div<\/span> <span class=\"hljs-attr\">class<\/span>=<span class=\"hljs-string\">\"box\"<\/span>&gt;<\/span>Scroll<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">div<\/span>&gt;<\/span>\n...<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">HTML, XML<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">xml<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h3 id=\"2-adding-the-css\" class=\"wp-block-heading\">2. Adding the CSS <\/h3>\n\n\n\n<p>In this case, we will be wrapping the code in a media query to make sure that it only applies when the user preference allows motion. Otherwise images would never become visible without the animation.<\/p>\n\n\n\n<p>We then set the initial opacity of the image to 0, the scale to 0.8, and add the <code>animation-timeline: view();<\/code>&nbsp;property.<\/p>\n\n\n\n<p>Note we are also using the <code><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/animation-range\" rel=\"nofollow noopener\" target=\"_blank\">animation-range<\/a><\/code>&nbsp;property. In this case, we are using it to tell at what point in the viewport we want the images to start animating and at what point we want the animation to finish.<\/p>\n\n\n\n<p>In this specific case, we want images to start animating when they are 50px away from the bottom of the viewport. We also want them to finish the animation when they are 36% away from the bottom of the viewport.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-7\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\"><span class=\"hljs-keyword\">@media<\/span> (<span class=\"hljs-attribute\">prefers-reduced-motion:<\/span> no-preference){\n  <span class=\"hljs-selector-tag\">img<\/span>{\n    <span class=\"hljs-attribute\">opacity<\/span>: <span class=\"hljs-number\">0<\/span>;\n    <span class=\"hljs-attribute\">scale<\/span>: <span class=\"hljs-number\">0.8<\/span>;\n    <span class=\"hljs-attribute\">animation<\/span>: fade-in linear forwards;\n    <span class=\"hljs-attribute\">animation-timeline<\/span>: <span class=\"hljs-built_in\">view<\/span>();\n    <span class=\"hljs-attribute\">animation-range<\/span>: <span class=\"hljs-number\">50px<\/span> <span class=\"hljs-number\">36%<\/span>;\n  }\n\n  <span class=\"hljs-keyword\">@keyframes<\/span> fade-in {\n    <span class=\"hljs-selector-tag\">to<\/span> {\n      <span class=\"hljs-attribute\">opacity<\/span>: <span class=\"hljs-number\">1<\/span>;\n      <span class=\"hljs-attribute\">scale<\/span>: <span class=\"hljs-number\">1<\/span>;\n    }\n  }\n}\n\n<span class=\"hljs-selector-class\">.box<\/span> {\n  <span class=\"hljs-attribute\">height<\/span>: <span class=\"hljs-number\">60vh<\/span>;\n  <span class=\"hljs-attribute\">padding<\/span>: <span class=\"hljs-number\">30px<\/span> <span class=\"hljs-number\">0<\/span> <span class=\"hljs-number\">0<\/span> <span class=\"hljs-number\">0<\/span>;\n  <span class=\"hljs-attribute\">text-align<\/span>: center;\n  <span class=\"hljs-attribute\">background<\/span>: <span class=\"hljs-number\">#4e4e4e<\/span>;\n  <span class=\"hljs-attribute\">width<\/span>: <span class=\"hljs-number\">400px<\/span>;\n  <span class=\"hljs-attribute\">margin<\/span>: <span class=\"hljs-number\">30px<\/span> auto;\n  <span class=\"hljs-attribute\">border-radius<\/span>: <span class=\"hljs-number\">12px<\/span>;\n  <span class=\"hljs-attribute\">font-size<\/span>: <span class=\"hljs-number\">1.4em<\/span>;\n  <span class=\"hljs-attribute\">color<\/span>: white;\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-7\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Something&#8217;s not clear? Then this video can come in handy for you:<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe title=\"Incredible scroll-based animations with CSS-only\" width=\"500\" height=\"281\" data-src=\"https:\/\/www.youtube.com\/embed\/UmzFk68Bwdk?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" data-load-mode=\"1\"><\/iframe>\n<\/div><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"scrolling-animation-with-vanilla-javascript\">Scrolling Animation with Vanilla JavaScript and CSS<\/h2>\n\n\n\n<p>Vanilla JavaScript, despite its fancy name, is not a library, it is just plain old JavaScript. So don&#8217;t get confused by the &#8220;fancy&#8221; name.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"1.-setup-the-page\">1. Setup the Page<\/h3>\n\n\n\n<p>First things first,  create a web page.  Just a simple layout with multiple sections.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-8\" data-shcb-language-name=\"HTML, XML\" data-shcb-language-slug=\"xml\"><span><code class=\"hljs language-xml\"><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">section<\/span> <span class=\"hljs-attr\">class<\/span>=<span class=\"hljs-string\">\"container\"<\/span>&gt;<\/span>\n  <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">h2<\/span>&gt;<\/span>Caption<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">h2<\/span>&gt;<\/span>\n  <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">div<\/span> <span class=\"hljs-attr\">class<\/span>=<span class=\"hljs-string\">\"text-container\"<\/span>&gt;<\/span>\n    <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">div<\/span> <span class=\"hljs-attr\">class<\/span>=<span class=\"hljs-string\">\"text-box\"<\/span>&gt;<\/span>\n      <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">h3<\/span>&gt;<\/span>Section Text<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">h3<\/span>&gt;<\/span>\n      <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">p<\/span>&gt;<\/span>Random text<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">p<\/span>&gt;<\/span>\n    <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">div<\/span>&gt;<\/span>\n    <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">div<\/span> <span class=\"hljs-attr\">class<\/span>=<span class=\"hljs-string\">\"text-box\"<\/span>&gt;<\/span>\n      <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">h3<\/span>&gt;<\/span>Section Text<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">h3<\/span>&gt;<\/span>\n      <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">p<\/span>&gt;<\/span>Random text<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">p<\/span>&gt;<\/span>\n    <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">div<\/span>&gt;<\/span>\n    <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">div<\/span> <span class=\"hljs-attr\">class<\/span>=<span class=\"hljs-string\">\"text-box\"<\/span>&gt;<\/span>\n      <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">h3<\/span>&gt;<\/span>Section Text<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">h3<\/span>&gt;<\/span>\n      <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">p<\/span>&gt;<\/span>Random text<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">p<\/span>&gt;<\/span>\n    <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">div<\/span>&gt;<\/span>\n  <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">div<\/span>&gt;<\/span>\n<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">section<\/span>&gt;<\/span>\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-8\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">HTML, XML<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">xml<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h3 class=\"wp-block-heading\" id=\"2.-styling-the-page-with-css\">2. Styling the Page with CSS<\/h3>\n\n\n\n<p>Add style attributes to your page and use CSS to define the scroll animation style, Now you need the class, <code>reveal<\/code>  for the sections you are animating and a new class name, <code>active<\/code>, for when it\u2019s activated.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-9\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\"><span class=\"hljs-selector-class\">.reveal<\/span>{\n  <span class=\"hljs-attribute\">position<\/span>: relative;\n  <span class=\"hljs-attribute\">transform<\/span>: <span class=\"hljs-built_in\">translateY<\/span>(<span class=\"hljs-number\">150px<\/span>);\n  <span class=\"hljs-attribute\">opacity<\/span>: <span class=\"hljs-number\">0<\/span>;\n  <span class=\"hljs-attribute\">transition<\/span>: <span class=\"hljs-number\">2s<\/span> all ease;\n}\n<span class=\"hljs-selector-class\">.reveal<\/span><span class=\"hljs-selector-class\">.active<\/span>{\n  <span class=\"hljs-attribute\">transform<\/span>: <span class=\"hljs-built_in\">translateY<\/span>(<span class=\"hljs-number\">0<\/span>);\n  <span class=\"hljs-attribute\">opacity<\/span>: <span class=\"hljs-number\">1<\/span>;\n}\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-9\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>With this, the <code>reveal<\/code> elements will be hidden until the <code>active<\/code> class is added. The <code>transform<\/code> and <code>transition<\/code> attributes define the scroll animation style, with this, the sections will fade in from the bottom and move, along the y-axis, towards the top. You can check this <a href=\"https:\/\/alvarotrigo.com\/blog\/css-transition-timing-function\/\">CSS Transition guide<\/a> if you have any doubts.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"3.-create-javascript-functions-to-target-the-elements\">3. Create JavaScript Functions to Target the Elements<\/h3>\n\n\n\n<p>We will need these functions to assign the new class name when they enter the viewport and we need it to trigger CSS animations on scroll.<\/p>\n\n\n\n<p><strong>Start by targeting all the<\/strong> <code>reveal<\/code> <strong>elements<\/strong> using  <code>document.querySelectorAll()<\/code>.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-10\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\"><span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> <span class=\"hljs-title\">reveal<\/span>(<span class=\"hljs-params\"><\/span>) <\/span>{\n  <span class=\"hljs-keyword\">var<\/span> reveals = <span class=\"hljs-built_in\">document<\/span>.querySelectorAll(<span class=\"hljs-string\">\".reveal\"<\/span>)\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-10\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>The scrolling animation needs to be triggered when it comes into view so we need to determine the element\u2019s position on the page, that is, the distance of the element from the top of the viewport.<\/p>\n\n\n\n<p><code>getBoundingClientRect().top<\/code> gives us this distance from the top of the viewport and  <code>window.innerHeight<\/code> will give us the height of the viewport.<\/p>\n\n\n\n<p>With this, we can set the conditions using <code>for<\/code>;<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-11\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\"><span class=\"hljs-keyword\">for<\/span> (<span class=\"hljs-keyword\">var<\/span> i = <span class=\"hljs-number\">0<\/span>; i &lt; reveals.length; i++) {\n  <span class=\"hljs-keyword\">var<\/span> windowHeight = <span class=\"hljs-built_in\">window<\/span>.innerHeight;\n  <span class=\"hljs-keyword\">var<\/span> elementTop = reveals&#91;i].getBoundingClientRect().top;\n  <span class=\"hljs-keyword\">var<\/span> elementVisible = <span class=\"hljs-number\">150<\/span>;\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-11\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>The variable, <code>windowHeight<\/code> is the height of the viewport, <code>elementTop<\/code> is the distance of the <code>reveal<\/code> element from the top of the viewpoint or, the length that has been scrolled, and <code>elementVisible<\/code>  is the height at which the element should be revealed to the user.<\/p>\n\n\n\n<p>You can determine when an element has scrolled a certain number of pixels into the page. Now <strong>define a function that displays the elements<\/strong> by adding and removing the <code>active<\/code> class. For this. use <code>if<\/code> and <code>else<\/code> statements. These will set the conditions for triggering the animation<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-12\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\"><span class=\"hljs-keyword\">if<\/span> (elementTop &lt; windowHeight - elementVisible) {\n  reveals&#91;i].classList.add(<span class=\"hljs-string\">\"active\"<\/span>);\n} <span class=\"hljs-keyword\">else<\/span> {\n  reveals&#91;i].classList.remove(<span class=\"hljs-string\">\"active\"<\/span>);\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-12\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>The complete <code>function<\/code> will look like this;<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-13\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\"><span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> <span class=\"hljs-title\">reveal<\/span>(<span class=\"hljs-params\"><\/span>) <\/span>{\n  <span class=\"hljs-keyword\">var<\/span> reveals = <span class=\"hljs-built_in\">document<\/span>.querySelectorAll(<span class=\"hljs-string\">\".reveal\"<\/span>);\n  <span class=\"hljs-keyword\">for<\/span> (<span class=\"hljs-keyword\">var<\/span> i = <span class=\"hljs-number\">0<\/span>; i &lt; reveals.length; i++) {\n    <span class=\"hljs-keyword\">var<\/span> windowHeight = <span class=\"hljs-built_in\">window<\/span>.innerHeight;\n    <span class=\"hljs-keyword\">var<\/span> elementTop = reveals&#91;i].getBoundingClientRect().top;\n    <span class=\"hljs-keyword\">var<\/span> elementVisible = <span class=\"hljs-number\">150<\/span>;\n    <span class=\"hljs-keyword\">if<\/span> (elementTop &lt; windowHeight - elementVisible) {\n      reveals&#91;i].classList.add(<span class=\"hljs-string\">\"active\"<\/span>);\n    } <span class=\"hljs-keyword\">else<\/span> {\n      reveals&#91;i].classList.remove(<span class=\"hljs-string\">\"active\"<\/span>);\n    }\n  }\n}\n\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-13\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Now we just pass it into an event listener to run it every time the visitor scrolls the page in any direction.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-14\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\"><span class=\"hljs-built_in\">window<\/span>.addEventListener(<span class=\"hljs-string\">\"scroll\"<\/span>, reveal, {<span class=\"hljs-attr\">passive<\/span>: <span class=\"hljs-literal\">true<\/span>});\n\n<span class=\"hljs-comment\">\/\/ To check the scroll position on page load<\/span>\nreveal();\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-14\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>That&#8217;s it! You have achieved <strong>CSS scroll animation<\/strong>.<\/p>\n\n\n\n<div class=\"wp-block-cp-codepen-gutenberg-embed-block cp_embed_wrapper\"><iframe id=\"cp_embed_PoKamZy\" data-src=\"\/\/codepen.io\/anon\/embed\/PoKamZy?height=450&amp;theme-id=1&amp;slug-hash=PoKamZy&amp;default-tab=css,result\" height=\"450\" scrolling=\"no\" frameborder=\"0\" allowfullscreen allowpaymentrequest name=\"CodePen Embed PoKamZy\" title=\"CodePen Embed PoKamZy\" class=\"cp_embed_iframe lazyload\" style=\"width:100%;overflow:hidden\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" data-load-mode=\"1\">CodePen Embed Fallback<\/iframe><\/div>\n\n\n\n<div class=\"wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex\">\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link wp-element-button\" href=\"https:\/\/codepen.io\/alvarotrigo\/pen\/PoKamZy\" title=\"See demo\" target=\"_blank\" rel=\"noopener nofollow\">See demo<\/a><\/div>\n<\/div>\n\n\n\n<p><strong>But, what if you want more?<\/strong> Right now, every section has the same uniform animation. Let\u2019s give each section a different scroll animation style.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"4.-animate-with-css\">4. Animate with CSS<\/h3>\n\n\n\n<p>First, we will assign classes in the HTML so we can reference them later on in our CSS to create the animations we want.<\/p>\n\n\n\n<p>Here&#8217;s how we would do it in our first section:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-15\" data-shcb-language-name=\"HTML, XML\" data-shcb-language-slug=\"xml\"><span><code class=\"hljs language-xml\"><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">section<\/span> <span class=\"hljs-attr\">class<\/span>=<span class=\"hljs-string\">\"container\"<\/span>&gt;<\/span>\n    <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">h2<\/span>&gt;<\/span>Caption<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">h2<\/span>&gt;<\/span>\n    <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">div<\/span> <span class=\"hljs-attr\">class<\/span>=<span class=\"hljs-string\">\"text-container reveal fade-bottom\"<\/span>&gt;<\/span>\n        <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">div<\/span> <span class=\"hljs-attr\">class<\/span>=<span class=\"hljs-string\">\"text-box\"<\/span>&gt;<\/span>\n            <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">h3<\/span>&gt;<\/span>Section Text<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">h3<\/span>&gt;<\/span>\n            <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">p<\/span>&gt;<\/span>Random text<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">p<\/span>&gt;<\/span>\n        <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">div<\/span>&gt;<\/span>\n        <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">div<\/span> <span class=\"hljs-attr\">class<\/span>=<span class=\"hljs-string\">\"text-box\"<\/span>&gt;<\/span>\n            <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">h3<\/span>&gt;<\/span>Section Text<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">h3<\/span>&gt;<\/span>\n            <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">p<\/span>&gt;<\/span>Random text<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">p<\/span>&gt;<\/span>\n        <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">div<\/span>&gt;<\/span>\n        <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">div<\/span> <span class=\"hljs-attr\">class<\/span>=<span class=\"hljs-string\">\"text-box\"<\/span>&gt;<\/span>\n            <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">h3<\/span>&gt;<\/span>Section Text<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">h3<\/span>&gt;<\/span>\n            <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">p<\/span>&gt;<\/span>Random text<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">p<\/span>&gt;<\/span>\n        <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">div<\/span>&gt;<\/span>\n    <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">div<\/span>&gt;<\/span>\n<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">section<\/span>&gt;<\/span>\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-15\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">HTML, XML<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">xml<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>And the same applies to any other sections we have in our HTML.<\/p>\n\n\n\n<p>Then, in our CSS we can assign them different animations like so:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-16\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\"><span class=\"hljs-selector-class\">.reveal<\/span> {\n  <span class=\"hljs-attribute\">position<\/span>: relative;\n  <span class=\"hljs-attribute\">opacity<\/span>: <span class=\"hljs-number\">0<\/span>;\n}\n<span class=\"hljs-selector-class\">.reveal<\/span><span class=\"hljs-selector-class\">.active<\/span> {\n  <span class=\"hljs-attribute\">opacity<\/span>: <span class=\"hljs-number\">1<\/span>;\n}\n<span class=\"hljs-selector-class\">.active<\/span><span class=\"hljs-selector-class\">.fade-bottom<\/span> {\n  <span class=\"hljs-attribute\">animation<\/span>: fade-bottom <span class=\"hljs-number\">1s<\/span> ease-in;\n}\n<span class=\"hljs-selector-class\">.active<\/span><span class=\"hljs-selector-class\">.fade-left<\/span> {\n  <span class=\"hljs-attribute\">animation<\/span>: fade-left <span class=\"hljs-number\">1s<\/span> ease-in;\n}\n<span class=\"hljs-selector-class\">.active<\/span><span class=\"hljs-selector-class\">.fade-right<\/span> {\n  <span class=\"hljs-attribute\">animation<\/span>: fade-right <span class=\"hljs-number\">1s<\/span> ease-in;\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-16\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Define the animations using Keyframes. The <code>transform<\/code> style attribute can bring a dynamic feel to your page and it can be added here. Another attribute you can add is <code>transition<\/code>, which is the time it takes for the element to load completely, but the 1s in the animation attribute achieve the same result.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-17\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\"><span class=\"hljs-keyword\">@keyframes<\/span> fade-bottom {\n  0% {\n    <span class=\"hljs-attribute\">transform<\/span>: <span class=\"hljs-built_in\">translateY<\/span>(<span class=\"hljs-number\">50px<\/span>);\n    <span class=\"hljs-attribute\">opacity<\/span>: <span class=\"hljs-number\">0<\/span>;\n  }\n  100% {\n    <span class=\"hljs-attribute\">transform<\/span>: <span class=\"hljs-built_in\">translateY<\/span>(<span class=\"hljs-number\">0<\/span>);\n    <span class=\"hljs-attribute\">opacity<\/span>: <span class=\"hljs-number\">1<\/span>;\n  }\n}\n<span class=\"hljs-keyword\">@keyframes<\/span> fade-left {\n  0% {\n    <span class=\"hljs-attribute\">transform<\/span>: <span class=\"hljs-built_in\">translateX<\/span>(-<span class=\"hljs-number\">100px<\/span>);\n    <span class=\"hljs-attribute\">opacity<\/span>: <span class=\"hljs-number\">0<\/span>;\n  }\n  100% {\n    <span class=\"hljs-attribute\">transform<\/span>: <span class=\"hljs-built_in\">translateX<\/span>(<span class=\"hljs-number\">0<\/span>);\n    <span class=\"hljs-attribute\">opacity<\/span>: <span class=\"hljs-number\">1<\/span>;\n  }\n}\n<span class=\"hljs-keyword\">@keyframes<\/span> fade-right {\n  0% {\n    <span class=\"hljs-attribute\">transform<\/span>: <span class=\"hljs-built_in\">translateX<\/span>(<span class=\"hljs-number\">100px<\/span>);\n    <span class=\"hljs-attribute\">opacity<\/span>: <span class=\"hljs-number\">0<\/span>;\n  }\n  100% {\n    <span class=\"hljs-attribute\">transform<\/span>: <span class=\"hljs-built_in\">translateX<\/span>(<span class=\"hljs-number\">0<\/span>);\n    <span class=\"hljs-attribute\">opacity<\/span>: <span class=\"hljs-number\">1<\/span>;\n  }\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-17\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>You can change the <code>transform<\/code> values and <code>animation<\/code> attributes to achieve more variety.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"5.-final-result\">5. Final Result<\/h3>\n\n\n\n<div class=\"wp-block-cp-codepen-gutenberg-embed-block cp_embed_wrapper\"><iframe id=\"cp_embed_XWaYRKK\" data-src=\"\/\/codepen.io\/anon\/embed\/XWaYRKK?height=450&amp;theme-id=1&amp;slug-hash=XWaYRKK&amp;default-tab=css,result\" height=\"450\" scrolling=\"no\" frameborder=\"0\" allowfullscreen allowpaymentrequest name=\"CodePen Embed XWaYRKK\" title=\"CodePen Embed XWaYRKK\" class=\"cp_embed_iframe lazyload\" style=\"width:100%;overflow:hidden\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" data-load-mode=\"1\">CodePen Embed Fallback<\/iframe><\/div>\n\n\n\n<div class=\"wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex\">\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link wp-element-button\" href=\"https:\/\/codepen.io\/alvarotrigo\/pen\/XWaYRKK\" title=\"See demo\" target=\"_blank\" rel=\"noopener nofollow\">See demo<\/a><\/div>\n<\/div>\n\n\n\n<p>You could animate individual blocks of text, let each paragraph load one after the other. Just assign the class name to whatever you want, style and animate with CSS, sprinkle a little vanilla Js and watch the magic.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"animating-the-navigation-bar-on-scroll\">Animating the Navigation Bar on Scroll<\/h2>\n\n\n\n<p>To add another practical <strong>example of using animations on scroll<\/strong>, we will animate a navigation bar based on the scroll position of the page.<\/p>\n\n\n\n<p>We can use our previous example and add a navigation bar to it. Let&#8217;s see how to do it.<\/p>\n\n\n\n<p>Feel free to check out <a href=\"https:\/\/alvarotrigo.com\/blog\/sticky-navbar\/\">how to create a sticky or fixed navbar<\/a> if you want to get into more details.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"1.-setup-the-navbar-to-animate\">1. Setup the NavBar to animate<\/h3>\n\n\n\n<p>First, the HTML:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-18\" data-shcb-language-name=\"HTML, XML\" data-shcb-language-slug=\"xml\"><span><code class=\"hljs language-xml\"><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">nav<\/span>&gt;<\/span>\n  <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">a<\/span> <span class=\"hljs-attr\">href<\/span>=<span class=\"hljs-string\">\"#home\"<\/span> <span class=\"hljs-attr\">class<\/span>=<span class=\"hljs-string\">\"active\"<\/span>&gt;<\/span>Home<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">a<\/span>&gt;<\/span>\n  <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">a<\/span> <span class=\"hljs-attr\">href<\/span>=<span class=\"hljs-string\">\"#about\"<\/span>&gt;<\/span>About<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">a<\/span>&gt;<\/span>\n  <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">a<\/span> <span class=\"hljs-attr\">href<\/span>=<span class=\"hljs-string\">\"#services\"<\/span>&gt;<\/span>Services<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">a<\/span>&gt;<\/span>\n  <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">a<\/span> <span class=\"hljs-attr\">href<\/span>=<span class=\"hljs-string\">\"#contact\"<\/span>&gt;<\/span>Contact<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">a<\/span>&gt;<\/span>\n<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">nav<\/span>&gt;<\/span>\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-18\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">HTML, XML<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">xml<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h3 class=\"wp-block-heading\" id=\"2.-style-the-navbar-with-css\">2. Style the NavBar With CSS<\/h3>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-19\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\"><span class=\"hljs-selector-tag\">a<\/span> {\n  <span class=\"hljs-attribute\">text-decoration<\/span>: none;\n}\n<span class=\"hljs-selector-tag\">ul<\/span> {\n  <span class=\"hljs-attribute\">list-style<\/span>: none;\n}\n<span class=\"hljs-selector-tag\">header<\/span> {\n  <span class=\"hljs-attribute\">position<\/span>: fixed;\n  <span class=\"hljs-attribute\">top<\/span>: <span class=\"hljs-number\">0<\/span>;\n  <span class=\"hljs-attribute\">left<\/span>: <span class=\"hljs-number\">0<\/span>;\n  <span class=\"hljs-attribute\">width<\/span>: <span class=\"hljs-number\">100%<\/span>;\n  <span class=\"hljs-attribute\">z-index<\/span>: <span class=\"hljs-number\">1000<\/span>;\n  <span class=\"hljs-attribute\">background<\/span>: <span class=\"hljs-number\">#42455a<\/span>;\n  <span class=\"hljs-attribute\">padding<\/span>: <span class=\"hljs-number\">20px<\/span>;\n  <span class=\"hljs-attribute\">text-align<\/span>: center;\n  <span class=\"hljs-attribute\">border-bottom<\/span>: <span class=\"hljs-number\">1px<\/span> solid <span class=\"hljs-number\">#00c2cb<\/span>;\n}\n<span class=\"hljs-selector-tag\">header<\/span> <span class=\"hljs-selector-tag\">nav<\/span> <span class=\"hljs-selector-tag\">a<\/span> {\n  <span class=\"hljs-attribute\">padding<\/span>: <span class=\"hljs-number\">10px<\/span> <span class=\"hljs-number\">20px<\/span>;\n  <span class=\"hljs-attribute\">font-size<\/span>: <span class=\"hljs-number\">2rem<\/span>;\n  <span class=\"hljs-attribute\">color<\/span>: <span class=\"hljs-number\">#e0ffff<\/span>;\n  <span class=\"hljs-attribute\">border-radius<\/span>: <span class=\"hljs-number\">5px<\/span>;\n  <span class=\"hljs-attribute\">letter-spacing<\/span>: <span class=\"hljs-number\">0.5px<\/span>;\n}\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-19\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Then you add the link styling for when the animation becomes <code>active<\/code>, you can combine this with the <code>hover<\/code> style, it\u2019s your choice;<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-20\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\"><span class=\"hljs-selector-tag\">header<\/span> <span class=\"hljs-selector-tag\">nav<\/span> <span class=\"hljs-selector-tag\">a<\/span><span class=\"hljs-selector-pseudo\">:hover<\/span>,\n<span class=\"hljs-selector-tag\">header<\/span> <span class=\"hljs-selector-tag\">nav<\/span> <span class=\"hljs-selector-tag\">a<\/span><span class=\"hljs-selector-class\">.active<\/span> {\n  <span class=\"hljs-attribute\">background<\/span>: <span class=\"hljs-number\">#00c2cb<\/span>;\n  <span class=\"hljs-attribute\">color<\/span>: <span class=\"hljs-number\">#42455a<\/span>;\n  <span class=\"hljs-attribute\">transition<\/span>: <span class=\"hljs-number\">0.5s<\/span> ease-out;\n  <span class=\"hljs-attribute\">letter-spacing<\/span>: <span class=\"hljs-number\">2px<\/span>;\n}\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-20\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h3 class=\"wp-block-heading\" id=\"3.-using-javascript-to-animate-our-navigation-bar\">3. Using JavaScript to Animate Our Navigation Bar<\/h3>\n\n\n\n<p>First target all the sections and links;<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-21\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\"><span class=\"hljs-keyword\">let<\/span> section = <span class=\"hljs-built_in\">document<\/span>.querySelectorAll(<span class=\"hljs-string\">'section'<\/span>);\n<span class=\"hljs-keyword\">let<\/span> menu = <span class=\"hljs-built_in\">document<\/span>.querySelectorAll(<span class=\"hljs-string\">'header nav a'<\/span>);\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-21\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Just like the first example, you want the navbar to be animated when the <code>section<\/code> is scrolled into view, for that, create an <code>onscroll<\/code> event and use <code>forEach<\/code> to call the function. For this, we need to declare the parameters and set the condition.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-22\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\"><span class=\"hljs-built_in\">window<\/span>.onscroll = <span class=\"hljs-function\"><span class=\"hljs-params\">()<\/span> =&gt;<\/span> {\n  section.forEach(<span class=\"hljs-function\"><span class=\"hljs-params\">i<\/span> =&gt;<\/span> {\n    <span class=\"hljs-keyword\">let<\/span> top = <span class=\"hljs-built_in\">window<\/span>.scrollY;\n    <span class=\"hljs-keyword\">let<\/span> offset = i.offsetTop - <span class=\"hljs-number\">150<\/span>;\n    <span class=\"hljs-keyword\">let<\/span> height = i.offsetHeight;\n    <span class=\"hljs-keyword\">let<\/span> id = i.getAttribute(<span class=\"hljs-string\">'id'<\/span>);\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-22\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><code>top<\/code> is the variable for <code>scrollY<\/code>, which is the length or number of pixels the viewport has been scrolled. <code>offsetTop<\/code> is the length of the element from the top of the viewport. <code>offsetHeight<\/code>  is the length of the sections and <code>getAttribute()<\/code> returns the value of an elements attributes, in this case, the <code>id<\/code> of the sections.<\/p>\n\n\n\n<p>Next, the conditions for execution so the links become <code>active<\/code> as you scroll down the page. The section should be inside the viewport so, the <code>offset<\/code> should be less than the length you scroll and also, the length from the top of the viewport and the length of the section or element should be more than the length you have scrolled;<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-23\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\"><span class=\"hljs-keyword\">if<\/span> (top &gt;= offset &amp;&amp; top &lt; offset + height) {\n  menu.forEach(<span class=\"hljs-function\"><span class=\"hljs-params\">link<\/span> =&gt;<\/span> {\n  \tlink.classList.remove(<span class=\"hljs-string\">'active'<\/span>);\n    <span class=\"hljs-built_in\">document<\/span>.querySelector(<span class=\"hljs-string\">'header nav a&#91;href*='<\/span> + id + <span class=\"hljs-string\">']'<\/span>).classList.add(<span class=\"hljs-string\">'active'<\/span>);\n\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-23\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>So now, when you scroll into a new section, the condition is met and the <code>active<\/code> attributes will be moved to the next link.<\/p>\n\n\n\n<p>Put it all together and it looks like this;<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-24\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\"><span class=\"hljs-keyword\">let<\/span> section = <span class=\"hljs-built_in\">document<\/span>.querySelectorAll(<span class=\"hljs-string\">'section'<\/span>);\n<span class=\"hljs-keyword\">let<\/span> menu = <span class=\"hljs-built_in\">document<\/span>.querySelectorAll(<span class=\"hljs-string\">'header nav a'<\/span>);\n<span class=\"hljs-built_in\">window<\/span>.onscroll = <span class=\"hljs-function\"><span class=\"hljs-params\">()<\/span> =&gt;<\/span> {\n  section.forEach(<span class=\"hljs-function\"><span class=\"hljs-params\">i<\/span> =&gt;<\/span> {\n    <span class=\"hljs-keyword\">let<\/span> top = <span class=\"hljs-built_in\">window<\/span>.scrollY;\n    <span class=\"hljs-keyword\">let<\/span> offset = i.offsetTop - <span class=\"hljs-number\">150<\/span>;\n    <span class=\"hljs-keyword\">let<\/span> height = i.offsetHeight;\n    <span class=\"hljs-keyword\">let<\/span> id = i.getAttribute(<span class=\"hljs-string\">'id'<\/span>);\n    <span class=\"hljs-keyword\">if<\/span> (top &gt;= offset &amp;&amp; top &lt; offset + height) {\n      menu.forEach(<span class=\"hljs-function\"><span class=\"hljs-params\">link<\/span> =&gt;<\/span> {\n        link.classList.remove(<span class=\"hljs-string\">'active'<\/span>);\n        <span class=\"hljs-built_in\">document<\/span>.querySelector(<span class=\"hljs-string\">'header nav a&#91;href*='<\/span> + id + <span class=\"hljs-string\">']'<\/span>)\n          .classList.add(<span class=\"hljs-string\">'active'<\/span>);\n      });\n    }\n  });\n};\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-24\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h3 class=\"wp-block-heading\" id=\"4.-result%3A-css-scroll-animation-%2B-navbar!\">4. Result: CSS Scroll Animation + NavBar!<\/h3>\n\n\n\n<div class=\"wp-block-cp-codepen-gutenberg-embed-block cp_embed_wrapper\"><iframe id=\"cp_embed_MWvXmja\" data-src=\"\/\/codepen.io\/anon\/embed\/MWvXmja?height=450&amp;theme-id=1&amp;slug-hash=MWvXmja&amp;default-tab=css,result\" height=\"450\" scrolling=\"no\" frameborder=\"0\" allowfullscreen allowpaymentrequest name=\"CodePen Embed MWvXmja\" title=\"CodePen Embed MWvXmja\" class=\"cp_embed_iframe lazyload\" style=\"width:100%;overflow:hidden\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" data-load-mode=\"1\">CodePen Embed Fallback<\/iframe><\/div>\n\n\n\n<div class=\"wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex\">\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link wp-element-button\" href=\"https:\/\/codepen.io\/alvarotrigo\/pen\/MWvXmja\" title=\"See demo\" target=\"_blank\" rel=\"noopener nofollow\">See demo<\/a><\/div>\n<\/div>\n\n\n\n<p>You can add the smooth <code>scroll-behavior<\/code>  attribute to give your website a truly dynamic feel. Make tweaks to the <code>animation<\/code> and <code>transform<\/code> style attributes and see what happens. Add a <code>transition-delay<\/code> to make it even more dramatic (check how to configure this attribute in <a href=\"https:\/\/alvarotrigo.com\/blog\/css-transition-timing-function\/#css-transition-delay\">this CSS Transition guide<\/a>)<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"conclusion\">Conclusion<\/h2>\n\n\n\n<p><strong>The scroll animation effect<\/strong> is a popular animation in todays websites and provide them with a modern and more dynamic look.<\/p>\n\n\n\n<p>\n    <a href=\"https:\/\/alvarotrigo.com\/fullPage\/\">\n        <video width=\"680\" height=\"382\" controls muted autoplay loop playsinline>\n        <source src= \"https:\/\/cdn.jsdelivr.net\/gh\/alvarotrigo\/blog-assets\/videos\/fullPage_intro.mp4\" type=\"video\/mp4\" \/>\n        <source src= \"https:\/\/cdn.jsdelivr.net\/gh\/alvarotrigo\/blog-assets\/videos\/fullPage_intro.webm\" type=\"video\/webm\"\/>\n        Your browser does not support the video tag.\n        <\/source><\/source><\/video>\n    <\/a>\n<\/p>\n\n\n\n<p>There are many other ways to create animations on scroll such as using components like <a href=\"https:\/\/alvarotrigo.com\/fullPage\/\">fullPage.js<\/a> that will combine animations and scroll in a beautiful way. Fullpage works by snapping full-screen sections into view when the visitor scrolls creating quite a unique and interesting user experience.<\/p>\n\n\n\n<p>And there are <a href=\"https:\/\/alvarotrigo.com\/blog\/7-scroll-text-animations-css-and-js\/\">many other cool animations you can use on scroll<\/a>. Just choose the one that fits your needs and creates the best scrolling experience for your visitors and page.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"related-articles\">Related articles<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/alvarotrigo.com\/blog\/7-scroll-text-animations-css-and-js\/\">7 scroll text animations [CSS &amp; JS]<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/alvarotrigo.com\/blog\/prevent-scroll-on-scrollable-element-js\/\">Prevent Scroll On Scrollable Elements [JS &amp; CSS]<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/alvarotrigo.com\/blog\/jquery-smooth-scroll\/\">Create jQuery smooth scrolling [3 ways]<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/alvarotrigo.com\/blog\/10-cool-css-animations-to-add-to-your-website\/\">10 cool CSS animations to add to your site<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/alvarotrigo.com\/blog\/css-snap-scroll-horizontally\/\">CSS scroll snap &#8211; Scroll Horizontally<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>CSS animations on scroll everywhere in nowadays websites. Learn how to trigger CSS animations on scroll in this article.<\/p>\n","protected":false},"author":13,"featured_media":4898,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[106],"tags":[9,17,67],"class_list":["post-4899","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-css","tag-css","tag-web","tag-web-design"],"acf":[],"_links":{"self":[{"href":"https:\/\/alvarotrigo.com\/blog\/wp-json\/wp\/v2\/posts\/4899","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/alvarotrigo.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/alvarotrigo.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/alvarotrigo.com\/blog\/wp-json\/wp\/v2\/users\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/alvarotrigo.com\/blog\/wp-json\/wp\/v2\/comments?post=4899"}],"version-history":[{"count":13,"href":"https:\/\/alvarotrigo.com\/blog\/wp-json\/wp\/v2\/posts\/4899\/revisions"}],"predecessor-version":[{"id":14936,"href":"https:\/\/alvarotrigo.com\/blog\/wp-json\/wp\/v2\/posts\/4899\/revisions\/14936"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/alvarotrigo.com\/blog\/wp-json\/wp\/v2\/media\/4898"}],"wp:attachment":[{"href":"https:\/\/alvarotrigo.com\/blog\/wp-json\/wp\/v2\/media?parent=4899"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/alvarotrigo.com\/blog\/wp-json\/wp\/v2\/categories?post=4899"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/alvarotrigo.com\/blog\/wp-json\/wp\/v2\/tags?post=4899"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}