Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scrolling issue on position fixed element on iOS

I am bulding a mobile project which has a number of modules having elements positioned as fixed. The issue which am facing is only on browsers running on iOS. The exact issue is that whenever I tr to scroll over the body of the page having , say the bottom toolbar, as fixed, the whole fixed element moves respectively with the scroll, and once the scroll ends completely, then only it comes back to its assigned place.

I have given the body of the page a relative css rule. Please help as this happens only on iOS.

 .add-to-block {
    background: #fff;
    position: fixed;
    bottom: 0px;
    right: 0px;
    display: block;
    height: auto;
    width: 100%;
    *(inner content element) {
        inner content element styling...
     }
}
like image 866
Aman Pandey Avatar asked Oct 20 '14 11:10

Aman Pandey


People also ask

How do you make fixed content go above IOS keyboard?

To force it work the same way as Mobile Chrome, you have to use position: absolute, height: 100% for the whole page or a container for your pseudo-fixed elements, intercept scroll, touchend, focus, and blur events. The trick is to put the tapped input control to the bottom of screen before it activates focus.

How we fix the Webkit overflow scrolling touch bug IOS?

The solution I found was to remove all the CSS that tricks the browser into using the GPU: -webkit-transform: translateZ(0px); -webkit-transform: translate3d(0,0,0); -webkit-perspective: 1000; By doing this, the '-webkit-overflow-scrolling: touch;' can still be included and still function as normal.

Which position will keep the element in the same place regardless of scrolling?

An element with position:fixed is fixed with respect to the viewport. It stays where it is, even if the document is scrolled.


4 Answers

Please try this, source here

    .add-to-block {
        transform: translate3d(0,0,0);
        .....
        .....
    }
like image 100
Abed Putra Avatar answered Oct 21 '22 04:10

Abed Putra


There is not really an easy answer to this as it has been a known issue on ios for a while (supposedly fixed in ios8) but this gives you a few ways to fix it: https://remysharp.com/2012/05/24/issues-with-position-fixed-scrolling-on-ios it details all the issues with position fixed on ios devices and possible ways to fix it if you need to use it.

like image 39
Steven Hoskins Avatar answered Oct 21 '22 02:10

Steven Hoskins


Safari allows you to scroll beyond the limits of the fixed div so that it can put in a nice bouncy effect. When you scroll past this point though, if there is a container that is scrollable, then subsequent touch events get handed off to this. Therefore scrolling does nothing for a bit until control gets handed back to the fixed div.

The fix is to give the container div the overflow-y: hidden style so that Safari does not hand off the touches, and we continue interacting with the fixed div.

like image 33
mrded Avatar answered Oct 21 '22 02:10

mrded


Add height: 100% and overflow: auto for fixed element.

Full example at https://codepen.io/astnt/pen/ExgOqeX

like image 27
Anton Starcev Avatar answered Oct 21 '22 02:10

Anton Starcev