Bug in Safari/Chrome on IOS: Scroll behavior issue with div using flex-direction:column-reverse

I have a basic div with flex-direction:column-reverse and a button that adds content to the div.

When adding values in Chrome, Firefox, Edge on Windows, and in Chrome and Firefox on my Galaxy S21 Ultra, everything behaves as expected. The div stays at scroll position 0 (which is the bottom since it is column-reverse). New elements are added until they exceed the div's size, then additional values are added outside the view, requiring manual scrolling to see them.

However, IOS devices, specifically Safari or Chrome on an iPhone 13, exhibit different behavior. With each new value added, the div automatically scrolls instead of remaining at position 0. After adding multiple values, these values become invisible and only reappear when manually scrolled by hand.

Changing the div from

flex-direction:column-reverse to flex-direction:coloumn resolves the issue, keeping the scroll position at 0 as intended.

Here is a simple example. Check it on an IOS mobile device to witness the "incorrect" behavior.

How can this be fixed to ensure the scroll position remains at 0?

Even implementing scroll logic in the addFunction(), like below, only seems to work in IOS devices after manual scrolling has occurred:

document.getElementById("content").scrollTo({top: 0,left: 0,behavior: "smooth"});

Answer №1

For those encountering a similar issue:

The only solution I discovered is to scroll to position -1, rather than scrolling to 0.

What doesn't work:

var addFunction = () => {
   //...
   document.getElementById("content").scrollTo({
       top: 0, //<-- not effective on IOS after initial rendering
       left: 0,
       behavior: "smooth"
   }); 
}

Here's what works:

var addFunction = () => {
   //...
   document.getElementById("content").scrollTo({
       top: 0, //<-- scroll to -1 instead of 0
       left: 0,
       behavior: "smooth"
   }); 
}

In IOS, there's an odd behavior where scrolling to 0 doesn't work initially (after the first render). However, it functions properly once you manually scroll once. By scrolling to -1 instead of 0, it also works from the start without manual intervention.

Any suggestions for a cleaner workaround would be greatly appreciated.

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

When using ng-repeat with Angular ui-bootstrap and tabs, the new tab will not be selected if there are no existing tabs present

To showcase the problem I'm facing, please refer to this link: http://codepen.io/pietrofxq/pen/ZLLJdr?editors=1010 Click on "remove tabs" and then on "add tab" The challenge at hand involves using a loop with ng-repeat to display tabs. At times, the ...

Issue with the transmission of FormData and string data to PHP

Struggling to properly handle sending file data and string data together through ajax to PHP. Having trouble retrieving the correct string data from $_POST[] in PHP, resulting in only receiving the initial alphabet of a string instead of the specific produ ...

What is the best way to align Bootstrap icons in the middle of buttons?

Currently, I am incorporating bootstrap icons into my design. Feel free to explore the provided DEMO. It showcases the issue of the bootstrap icons not aligning in the same line as the text inside the button. I am seeking advice on how to centralize the i ...

Is there an issue with invoking Spring controller methods from JavaScript (via ajax) that is causing them

Using JavaScript to send a request to a method in Spring controller, the code looks like this: <script language="javascript" type="text/javascript"> var xmlHttp function show() { if(typeof XMLHttpReques ...

Ways to adjust the CSS height of a fluid body and flexible footer

In a nutshell, I'm dealing with 3 elements: <div> <Header/> </div> <div> <Body/> </div> <div> <Footer/> </div> The header has a fixed height. ...

Tips for transferring information between two components when a button is clicked in Angular 2

I am currently working on a code that displays a table on the main page with two buttons, "Edit" and "Delete", for each row. When the Edit button is clicked, a modal opens up. My question is, how can I pass the "employee id" of a specific employee to the ...

Issues with Pdf.js functionality on Internet Explorer

Could someone shed some light on why this code isn't functioning in Internet Explorer? It works perfectly fine in Chrome. Snippet of my HTML: <head> <script type='text/javascript' src="//code.jquery.com/jquery-1.9.1.js"></sc ...

I'm having trouble getting my flex items to maintain a specific width and height while staying in a single line

I've been out of practice with flexbox for some time and I can't figure out why the width and height properties are not being applied to each flex item as expected. All the items seem to have an equal width, but not the width that I specified. Ad ...

Using NSUInteger to encode strings in both 32-bit and 64-bit systems

I'm currently grappling with the challenge of converting an NSUInteger into a string that is compatible with both 32-bit and 64-bit systems. I've noticed that NSUInteger is defined differently for each platform, so I want to ensure that my approa ...

Using PHP to perform live calculations with arrays in real time

Currently, I am working on developing a new system for a client that allows them to create bookings and invoices to send to their clients. One specific requirement my client has is the need for a table column to be added below the container columns in whi ...

Adjust the opacity of certain elements to be semi-transparent, with the exception of the one currently

I'm attempting to implement the :not selector in conjunction with :hover to create a visual effect where elements that are not being hovered over become semitransparent. My goal is as follows: 1) All elements start at 100% opacity 2) When an elemen ...

How about adding various colors in the background with layers?

I was recently given a task by a client to convert their picture art into CSS code. While I have successfully completed most of the task, I am facing difficulty in coloring the div similar to the example provided by the client. Here is the client's ve ...

Understanding how to retrieve a particular list item in JQuery without having the index in advance

I have a lengthy list that is broken down into various subheadings. How can I retrieve the second to last element of the list before a specific subheading, provided it is not the final element? Is it possible to do this if I know the ID of the subheading? ...

Injecting resolve into Angular controller and encountering undefined value in logging operation

My setup involves the following: .state('posts', { url: '/posts/{id}', templateUrl: 'posts.html', controller: 'postsController as postsCtrl', resolve: { post: getSinglePostWrapper ...

Implement a popmenu for navigation when the menu is too lengthy

Is there a way to create a dynamic breadcrumbs navigation that adjusts based on the page width, and displays certain elements in a dropdown menu if the navigation becomes too lengthy? For example, consider the following list: <div> <nav> ...

Managing a multitude of devices by connecting and communicating with all of them through a single CB

I am in the process of developing an iOS application that utilizes the CoreBluetooth library to manage and transfer data from multiple inertial measurement units equipped with HM-10 BLE 4.0 modules. While I can successfully connect, write, and read from a ...

How can I convert a UTC time field from MySQL into JavaScript?

I'm struggling to pinpoint the error in my date/time difference calculations. It seems to be related to timezone variations, but I can't figure out exactly where the problem lies. Below are all the components involved - can you help me identify t ...

Is it possible to utilize a .css file as the origin with @font-face?

Received a shortened path to a Gotham font... https://cloud.typography.com/[path shortened]/css/fonts.css Attempting to use it in a @font-face definition but facing issues with the src format: @font-face { font-family: 'Gotham'; src: url(" ...

Issue found in React Js test - TypeError: source.on does not exist as a function

I'm encountering an issue with my post request using multipart/form-data. Everything runs smoothly, except for the tests which are failing. When running the tests, I encounter an error message: TypeError: source.on is not a function. This is the code ...

What causes the unexpected outcome when applying theme overrides in Mui V5?

I am looking to adjust the border radius of all input fields in my project. Specifically, I would like the TextField component to have a border radius of https://i.stack.imgur.com/ULEGj.png instead of https://i.stack.imgur.com/NWmUe.png. According to the M ...