{"componentChunkName":"component---src-templates-blog-post-js","path":"/blog/2019-10-23-smooth-scroll/","result":{"data":{"markdownRemark":{"html":"<p>Greetings!</p>\n<p>Do you want to give your site that cool smooth scroll when someone clicks a link?</p>\n<!-- more -->\n<p>So, lets say you have an awesome page with different sections. You have several ways for allowing the user to get to them. Here are some examples:</p>\n<ol>\n<li>Good ol' scrolling,</li>\n<li>Click on a link and make the user insta-jump to the desired section,</li>\n<li>Click on a link and make the user go to the desired section with a cool smooth auto-scroll.</li>\n</ol>\n<p>Here we go with the CSS way to get that smooth auto-scroll:</p>\n<h2>The CSS</h2>\n<div class=\"gatsby-highlight\" data-language=\"css\"><pre class=\"language-css\"><code class=\"language-css\"><span class=\"token selector\">html</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token property\">scroll-behavior</span><span class=\"token punctuation\">:</span> smooth<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>Replacing <code class=\"language-text\">smooth</code> with <code class=\"language-text\">auto</code> gives you the default insta-jump behavior.</p>\n<h2>Consider users with motion sickness</h2>\n<p>Vestibular disorders arise when the parts of the inner ear and brain that process the sensory information involved with controlling balance and eye movement get damaged.</p>\n<p>Users with this disorders may suffer from motion sickness, which can make the experience of browsing the web quite unpleasent for them.</p>\n<p>As stated in <a href=\"https://developer.mozilla.org/es/docs/Web/CSS/scroll-behavior\">MDN</a>, you should use a CSS <code class=\"language-text\">prefers-reduced-motion</code> media query to disable smooth scrolling to account for users that have set their browsers to <code class=\"language-text\">reduced motion</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"css\"><pre class=\"language-css\"><code class=\"language-css\"><span class=\"token selector\">html</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token property\">scroll-behavior</span><span class=\"token punctuation\">:</span> smooth<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token atrule\"><span class=\"token rule\">@media</span> <span class=\"token punctuation\">(</span><span class=\"token property\">prefers-reduced-motion</span><span class=\"token punctuation\">:</span> reduce<span class=\"token punctuation\">)</span></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token selector\">html</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token property\">scroll-behavior</span><span class=\"token punctuation\">:</span> auto<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h2>Compatibility</h2>\n<p>This CSS property is supported in Chrome, Firefox and Opera. As of the date of publication of this blog post, it is not supported in Safari, Edge nor Internet Explorer.</p>\n<p>Cheers, have a good one!</p>","frontmatter":{"title":"Smooth scroll","date":"October 23rd, 2019","icon":"☕️"},"fields":{"readingTime":{"text":"2 min read"}}}},"pageContext":{"slug":"/2019-10-23-smooth-scroll/"}},"staticQueryHashes":["143701507","588331372"]}