Automated scrolling in Chrome is ineffective without initial manual scrolling

In order to create a smooth user experience for mobile users when the side-drawer menu is open, I have implemented overflow: hidden and height: 100vh on the App container (excluding the drawer) to prevent scrolling while the drawer is visible.

Typically, when the overflow and height properties are removed, the window will automatically scroll back to the top. To avoid this, I am saving the original scroll position before opening the drawer and restoring it when the drawer is closed using window.scrollTo(0, pos).

I have observed that Chrome does not allow programmatically scrolling until manual scrolling has been initiated. To test this behavior, I ran the following code:

if (!drawerIsOpen && drawerIsClosing) {
  let done = false;
  const interval = setInterval(() => {
    if (window.scrollY !== this.props.store.app.scrollPosition) {
      console.log('attempting');
      window.scrollTo(0, this.props.store.app.scrollPosition);
    } else {
      clearInterval(interval);
    }
  }, 50);
}

The interval continues running indefinitely, but as soon as the window is manually scrolled, Chrome allows programmable scrolling and stops the interval. This behavior was not replicated in Safari or Firefox.

Could this be related to which element has focus? Does Chrome delay updating its internal scroll position knowledge until user interaction occurs?

Answer №1

After some experimentation, I found that using

window.scrollBy(0, scrollPosition)
resolved the problems I was experiencing with both window.scrollTo() and document.body.scrollTop.

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

changing font size on a mobile-friendly site using javascript

Currently, I am designing a responsive webpage utilizing Bootstrap framework. Situated in the center of the screen is a text that reads: <p id="entershop" ><a class=no-deco href="shop.html">enter shop</a></p> Within the Bootstra ...

Consistent column heights within each row

I currently have Bootstrap implemented on my website and have integrated jQuery to adjust the height of each column to match the tallest one. However, the issue I am facing is that the height adjustment applies globally across the entire page, rather than ...

Guide on incorporating reusable component inputs in Vue 3

Does anyone have any tips on creating reusable component input in Vue 3? Similar to how it's done in React: For example, Using <Input /> as a reusable component in the parent component import { ref } from 'vue'; import Input from &a ...

Transform the Unix Timestamp into its corresponding Long original Timestamp value

I have a Unix timestamp that was stored in a MongoDB database as NumberLong(1385297660000000000). However, when I retrieve the timestamp and check it in Chrome's developer console, it shows up as: timestamp: Object _bsontype: "Long" high_ ...

In a React app, there are instances where `localstorage.getitem('key')` may result in returning null

I've encountered a strange issue while building a login form that sets a JWT token in localstorage. The problem arises when, despite being able to see the token in my console.log, setting localstorage.getitem('idToken') sometimes returns nul ...

Having trouble positioning the right side image on the Bootstrap 4 Landing page

Struggling to incorporate bootstrap 4 into my sample project for the right side background. I'm facing some conflicts and attempts to align it on the right side are not successful. Does anyone know how to do this correctly? Thank you // Navbar scr ...

What is the best way to synchronize CouchDB with multiple PouchDB instances in an AngularJS application?

I need help with my Angular project. I'm trying to figure out how to sync multiple PouchDB databases to a single CouchDB instance without losing any data. Can anyone provide some guidance or advice? ...

Transferring information to a subordinate view

I'm working on developing a single-page application and need to transfer data to a child view. After fetching the API using Axios, I am able to successfully log the data in the console. However, when trying to display the data in the child view, I en ...

Preventing selection of past dates with Material UI in ReactJS

I'm currently working on a date range picker using react material ui. The goal is to allow users to select a specific date and then disable all past dates from that selected date onward. How can I go about implementing this functionality in react mate ...

Error message received while converting webm video to images using Kagami/ffmpeg.js: Unable to locate an appropriate output format for '%04d.jpg'

These are the current versions: node v12.9.1, npm 6.10.2, [email protected] Repository: https://github.com/Kagami/ffmpeg.js The code in decode.js looks like this: const fs = require('fs'); const ffmpeg = require('ffmpeg.js'); c ...

What is the best approach for selecting and organizing MongoDB records, as well as identifying the following record for retrieval?

Currently, I have a stack of documents that needs to be filtered out based on specific criteria and then arranged alphabetically according to the string value within those documents — let's call it a "search result". Subsequently, I am required to l ...

Encountering issues with Office.context.document.getFileAsync function

I am experiencing a strange issue where, on the third attempt to extract a word document as a compressed file for processing in my MS Word Task Pane MVC app, it crashes. Here is the snippet of code: Office.context.document.getFileAsync(Office.FileType.Co ...

Explore ways to showcase a list of calendars through the Google API with the use of Java Script

I'm experiencing difficulties with displaying a list of accessible calendars from Google Calendar using the Google API. I am utilizing JavaScript and AJAX to achieve this. What specific methods do I need to implement? I have only come across event-re ...

Utilizing remote debugging for Internjs implemented on Selenium's ChromeDriver

When it comes to remotely debugging tests run by Internjs, the process involves running Chrome with Selenium and Chromedriver. To set up the debuggerAddress option for Chromedriver: debuggerAddress: '127.0.0.1:8765' However, upon running tests ...

Associate text with a color from a predetermined list (JavaScript)

As I work on adding tags to my website for blog posts, I have a specific vision in mind. Each tag should be assigned a unique background color selected from a predefined array of theme colors. My goal is to assign the same background color to tags with id ...

Prevent selection of specific weekdays in Kendo grid calendar

When editing a record in a Kendo grid with a date field, is there a way to only allow the selection of Monday and disable all other days of the week? ...

Grab the div, position it accurately, and initiate an ajax call

So many tasks on my plate, but let's prioritize. Within a <div class="showcase">, I have numerous <div class="game"> elements, each with an onclick="addpop('delpopup.php?id=something&pos=somethingelse&box=image')" Does ...

I require assistance in configuring the timing for an animation using Jquery

How can I adjust the timing (delay between two words) for this animation? If you need help, you can check out this link for guidance. Feel free to share your suggestions! ...

The JavaScript filter function will only return arrays that have matching IDs

How can I filter out book data based on the author's id? I have a list of books with various author ids, and I want to only return the books that match a specific author id. However, my current filtering method doesn't seem to work correctly as i ...

Turn off pagination for tables in Material-UI

Currently, I am utilizing the TablePagination component from Material-UI in my React project. Unfortunately, this component does not come with a built-in disabled prop. I do have a boolean variable called loading that I would like to utilize as a paramet ...