Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to style the iOS Safari overscroll/elastic scroll area?

Tags:

css

safari

webkit

In iOS Safari, when you scroll to the bottom of a web page, you are able to sort of "lift" the page up by trying to scroll again. I assume this is to assure the user that they have reached the end of the page. This area is empty and white by default. Is there a way to style this area with CSS? I'd like to add a background image if only to add flair. As everyone else is asking how to prevent the overscrolling I wanted to know if I could actually use it for something.

I tried adding a background image to the body tag and fixing it to the bottom but it wasn't visible through the overscroll. I feel like it might be impossible as it is part of Safari itself, and the webpage (and its control) has already ended.

like image 279
jdgregson Avatar asked Jun 09 '16 05:06

jdgregson


People also ask

What is overscroll-behavior?

The overscroll-behavior CSS property sets what a browser does when reaching the boundary of a scrolling area. It's a shorthand for overscroll-behavior-x and overscroll-behavior-y .

How do I stop CSS Overscrolling?

To do this (in Chrome, Firefox, and Edge), we can add the CSS property overscroll-behavior: contain to the overflow: auto element. This will prevent the "scroll chaining" behavior, which will, in turn, keep the mouse-wheel active within the target element.

How do I turn off scrolling In iOS?

Go to Settings and tap Accessibility. Turn on the feature, then use the slider to select a sensitivity level.


2 Answers

I know this is an old topic but it still came up first on my search results.

As of lately safari uses the "theme-color" meta tag for this.

For example if you use multiple themes:

  <meta name="theme-color" content="#f6f8fa" media="(prefers-color-scheme: light)">
  <meta name="theme-color" content="#161b22" media="(prefers-color-scheme: dark)">
like image 149
mathiasb Avatar answered Oct 04 '22 09:10

mathiasb


A few years later and I have found that this is (sort of) possible, using fixed positioning and z-indexes. Assuming your content height is greater than your screen height and your content is wrapped in a div, if you put something in another div with the following class it should appear in the iOS overscroll area:

.ios-peek {
    position: fixed;
    z-index: -1;
    bottom: 0;
    left: 0;
}

And here is a proof-of-concept page which seeks to accomplish this even with content that is shorter than the screen height:

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<style>
* {
    margin: 0;
}

#content {
    min-height: 100vh;
    height: 100%;
    background-color: #fff;
}

#bottom-text {
    position: absolute;
    bottom: 0;
}

.ios-peek {
    position: fixed;
    z-index: -1;
    bottom: 0;
    left: 0;
}
</style>
</head>
<body>
    <div id="content">
        <h1>Blah</h1>
        <p>Blah blah blah blah blah blah blah blah blah...</p>
    </div>
    <div id="bottom-text">
        <h3>You're at the bottom, nothing else to see...</h3>
    </div>
    <div class="ios-peek">
        <h1>hi there</h1>
    </div>
</body>
</html>
like image 25
jdgregson Avatar answered Oct 04 '22 10:10

jdgregson