The smooth scroll functionality is completely nonfunctional

My smooth scroll feature doesn't seem to be working, despite adding

overflow-y: scroll; scroll-behavior: smooth;
to my code. Here's the snippet:

#container{
    overflow-y: scroll;
    scroll-behavior: smooth;
}
.topTab{
bottom: 0;
position: fixed;
font-size: 25px;
color: white;
}
.pg{
  font-size: 100px;
  height: 100vh;
  background-color: blue;
  text-align: center;
}

a{
 color: white;
}
<div class = "topTab">
  <li><a href="#1">1</a></li>
  <li><a href="#2">2</a></li>
  <li><a href="#3">3</a></li>
</div>

<div id = "container">
<div id = "1" class= "pg">1</div>
<div id = "2" class = "pg">2</div>
<div id = "3" class = "pg">3</div>
</div>

Answer №1

To modify the existing auto scroll configurations, make sure to include !important in your CSS code.

*, html {

    scroll-behavior: smooth !important;
}

Answer №2

Encountering a similar problem on the latest version of Chrome (88.0.4324.182), I managed to resolve it by activating the smooth scrolling feature through the following URL:

chrome://flags/#smooth-scrolling 

Answer №3

I encountered a problem with my computer where certain functions were not working properly. After investigating, I discovered that the issue was due to my Windows settings for peak performance, which had disabled all animations. Once I turned off this setting, everything started functioning as expected. [To access the appearance and performance settings in Windows, you can simply type "Adjust the appearance and performance of Windows" into the start menu search bar to bring up the dialog box and re-enable all animations]

Answer №4

For those struggling with getting scroll-behavior:smooth to work on the html element, a simple solution that worked for me was also adding it to the body element.

    html, body { 
      scroll-behavior: smooth
    }

Answer №5

  • Give this a shot...

html {
  scroll-behavior: smooth;
}

#container{
    overflow-y: scroll;
}
.topTab{
bottom: 0;
position: fixed;
font-size: 25px;
color: white;
}
.pg{
  font-size: 100px;
  height: 100vh;
  background-color: blue;
  text-align: center;
}

a{
 color: white;
}
<div class = "topTab">
  <li><a href="#1">1</a></li>
  <li><a href="#2">2</a></li>
  <li><a href="#3">3</a></li>
</div>

<div id = "container">
<div id = "1" class= "pg">1</div>
<div id = "2" class = "pg">2</div>
<div id = "3" class = "pg">3</div>
</div>

Answer №6

If you encounter issues with this in Vue:

Simply include the following code snippet


<style>
html {
  scroll-behavior: smooth;
}
</style>

in your App.vue file.

Answer №7

After exhausting all options with no success, I finally attempted the last solution. Surprisingly, it turns out that Windows 11 had "Animation effects" disabled by default. This was news to me. Once I enabled it, everything began functioning properly. It's puzzling how altering an animation setting in Windows could impact my browser, but there seems to be a correlation.

Answer №8

My issue with Chrome was resolved when I applied the following solution:

html:focus-within {
  scroll-behavior: smooth;
}

For further information, check out Css-tricks article titled "Improving Smooth Scrolling with Find-on-Page"

Answer №9

Make sure to check if your browser supports the scroll-behavior property.

Verify browser compatibility for scroll-behavior

If your browser is compatible with this feature but smooth scrolling still isn't working, don't worry, it's not an issue with your code. You just need to adjust a small setting in your browser.

If you are using Chrome, navigate to "chrome://flags/", use ctrl+f to search for smooth scrolling, enable it, and then restart your browser to see the changes take effect.

Answer №10

While browsing through various responses, I came across a suggestion to investigate the relationship between Windows performance settings and scrolling smoothness. Upon changing the settings to "adjust for best appearance" in System Properties > Performance Options, I noticed a significant improvement in scrolling fluidity.

Answer №11

Unfortunately, this functionality will cease to operate if your device has a preference for reduced motion...

I used to believe that overriding elements not set to "auto" was poor practice, but it appears to be common now.

Answer №12

No matter how hard I tried, I couldn't find a solution.

The steps that finally brought success to my system were:

  1. Restarting the frontend client.
  2. Adding overflow-y: "auto"
  3. Moving scroll-behavior : smooth from html outside container to inside container fixed the issue

Note: Applying these CSS changes to the parent container instead of the actual container did not resolve the problem for me.

#container{
    overflow-y: auto;
    scroll-behavior: smooth;
}

Answer №13

After experimenting with different options, I developed a personalized solution using the easeOutSine function:

function scrollAnimation (initial?: number) {
  if (document.documentElement && document.documentElement.scrollTop && document.documentElement.scrollTop > 10) {
    if (typeof initial === 'undefined') initial = document.documentElement.scrollTop;

    const progress = (initial - document.documentElement.scrollTop + 1)/initial;
    document.documentElement.scrollTo({top: initial*(1-easeOutSine(progress))});
    setTimeout(() => {
      scrollAnimation(initial);
    }, 10);
  }
}

function easeOutSine(x: number): number {
  return Math.sin((x * Math.PI) / 2);
}

Since the default smooth option was not consistent in my tests and I could not rely on user settings, this tailored approach proved to be more reliable.

You have control over the animation speed by adjusting the time interval in the setTimeout function.

Answer №14

Hey there, when working with a container, it's important to specify the scroll behavior separately.

#container {
    overflow-y: scroll;
    scroll-behavior: smooth;
}

If you want the entire website to scroll smoothly, you can use this code snippet:

* {
    scroll-behavior: smooth;
}

Answer №15

Here's a simple CSS solution that I implement in all of my projects - it works consistently and efficiently:

*,
*::after,
*::before {
  margin: 0;
  padding: 0;
  box-sizing: border-box !important;
  scroll-behavior: smooth;
}

html {
  --scroll-behavior: smooth !important;
  scroll-behavior: smooth !important;
}

Answer №16

To set up smooth scrolling on your live server, simply copy and paste the following link into your browser:

chrome://flags/#smooth-scrolling 

Once you have done that, a new tab will open where you can enable the smooth scrolling option before relaunching the tab. If you want to incorporate smooth scrolling into your website, make sure to include the following code in your code editor:

<html lang="en" style="scroll-behavior: smooth;" >

Answer №17

After some troubleshooting, I discovered that my problem stemmed from using the English spelling of 'behaviour' instead of the American-English version. When properly spelled, scroll-behavior: smooth; should function correctly with the html selector. It seems this issue did not apply to @James_Lee.

Answer №18

While my issue may have seemed trivial, it's possible that others are facing the same problem and could benefit from this solution.

In my case, I mistakenly altered my anchor links from <a href="#Home"> to

<a href="index.html#Home">

Initially, the anchor links smoothly scrolled within my IDE's server preview browser and locally in all browsers. However, once I uploaded my site to Cloudflare Pages, the smooth scrolling was replaced with a jumpy effect.

Reverting the anchor link back to <a href="#Home">, restored the smooth scrolling functionality on my staging site hosted on Cloudflare Pages.

Answer №19

Utilized a petite library due to the inconsistency of browsers/OS's in working with the native smooth scroll feature.

npm install --save zenscroll

import zenscroll from 'zenscroll';

zenscroll.setup();

Answer №20

#wrapper{
    overflow-y: auto;

    scroll-behavior: smooth !important;
}

.headerTab{
bottom: 0;
position: fixed;
font-size: 25px;
color: white;
}
.content{
  font-size: 100px;
  height: 100vh;
  background-color: blue;
  text-align: center;
}

a{
 color: white;
}

Give this code snippet a shot!

Answer №21

When faced with a similar issue, I found that adjusting the settings - easy operations - show animation in Windows within Windows 10 resolved the problem. (It is important to note that checking this setting can improve mouse wheel scrolling even if the scroll-behavior in the CSS is set correctly.)

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Unsolved PHP variable issue

I recently delved into a tutorial on developing a file upload feature, but encountered an issue with the "unresolved variable total_line" in the index.php file, despite having declared total_line in another PHP file. The error occurs when trying to access ...

Is it necessary to display a div if the chosen Datatables row contains a span?

Currently, I am dealing with a table that has attachments, but for illustration purposes, I'm using a copyright icon. My challenge lies in displaying or hiding the .newImage block based on whether the row contains a span element (copyright icon) when ...

HTML footer that remains fixed to the bottom of the browser window

I am creating a web application and facing an issue with keeping the footer at the bottom of the window. Whenever the content exceeds the window size, the footer gets pushed down. Is there a method to make the footer stick to the bottom of the window while ...

Overlaying Colors on PNG Images with CSS

I have been searching for a solution to this issue, but have yet to find one. My dilemma involves a PNG image with a transparent background. I want to change the color of the image itself (not the transparent background) using CSS. I know there should be ...

Various spacings between letters are used for various font styles

After carefully choosing a letter-spacing that enhances the readability of my webpage, I encountered an issue when Arial was used as a backup font for browsers that don't support embedded fonts. The letter-spacing got all messed up and caused overflow ...

Aligning text beneath a positioned span element

I have a code snippet where I am trying to center a number within a div and then center the units right below the number. The number is centered correctly, but the units are not aligning as desired. How can I achieve this layout? div.div1 { height: 20 ...

Image with a custom background color and div overlay

Is it possible to have a colored background with an image in the content div? <body style="background-color: black; "> <div id="header" style="background: url('xxx11.png') repeat left top;"> </div> <div id="#containe ...

Aligning HTML elements side by side

I am currently utilizing reactJS to create a form. Within this form, I am attempting to include a text field, a button for copying the text to the clipboard, and a hyperlink that redirects to a valid website. The issue I am facing is evident in the provid ...

HTML drag-and-drop setDragImage fails to show ghost image on initial drag operation

Currently, I am working on developing a drag and drop menu feature that allows users to drag an image thumbnail from one div to a canvas element. The main issue I am facing is that the source div uses a sprite for displaying its background thumbnail. As a ...

Floating with Bootstrap Utility

Have you ever wondered about the proper usage of bootstrap float utility? Check out this example: <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/> <div class="row"> <div class=" ...

Converting JSON to HTML is like translating a digital language

I am in the process of developing a web application, and I have implemented an ajax request that queries a database (or database cache) and returns a large JSON object. Since I am new to working with JSON, when my PHP script retrieves data from the databas ...

The primary content division is trapped behind the side navigation bar

Why is my sidebar fixed on the left of the screen overlapping with the main content? I want the main content to be displayed next to the navbar and scroll up and down while keeping the nav bar in place, but no matter what styling I apply, it doesn't w ...

Fixed position navbar toggler

Hey there! I currently have a centralized navbar layout for Desktop. However, my aim is to also center it on the mobile version. Basically, this navigation bar appears when scrolled downwards with icons like this. Therefore, I'm looking for assistan ...

Encountering an unusual hash code when implementing Google Tag Manager in a Next.js project was

I am currently using Next.js and have added Google Tag Manager through a script <script dangerouslySetInnerHTML={{ __html: `(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': new Date().getTime(),event:'gtm.js'});var ...

What is the best way to add HTML formatted text into Outlook?

In my Emacs, I've generated this syntax-highlighted code snippet and now want to paste it into an Outlook email with rendered HTML (without the actual HTML code). <pre> <span style="color: #a020f0; background-color: gtk_selection_bg_color;"& ...

How do I eliminate excess space following the resizing of the Material UI Drawer component?

I adjusted the size of my MUI drawer to a specific width and now I am facing an issue where there is extra space left after resizing. This results in a margin-like space between the drawer and the Lorem Ipsum text content. My goal is to eliminate this rema ...

Avoiding the collapse of the Bootstrap 4 navbar

Having trouble with the navbar collapsing on itself? The issue seems to occur around 1280px window size, but works fine when the window is wider or narrower. https://www.bootply.com/AcsaaqReAL .navbar-custom { background-color: #333333; border- ...

Map of UK Counties and Illustrated Maps

Looking for a map of the UK displaying counties that users can click on? I've discovered that instead of using flash, image maps with a large png county map will do the trick. However, the process of manually clicking dots between counties could take ...

ways to modify hash URLs using JavaScript

I am looking to add separate hash links for my Facebook and Instagram social media pages. I also want to change the text color to blue for Facebook and yellow for Instagram. How can I achieve this using JavaScript? let socialMediaData = [{ s_media: &apo ...

Creating a dynamic table inside a flex-grow container without disrupting the layout: A step-by-step guide

Currently, I am in the process of designing a responsive layout using Bootstrap 5.3 which consists of a NavBar, SideBar, ContentPanel, and StatusBar. The goal is to ensure that the application always occupies 100% of the view-height and view-width, display ...