Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Image in HTML element overflow

Chrome and other browsers have overscroll (also called elastic scroll, or rubber band scroll) for the html element. (See here or here.)

I want an image in the html overscroll as an Easter egg, a bit like the Slack for iOS Easter egg. (See "You are up to date." in the screenshot.)

Enter image description here

The CSS

html {     background: green; } 

gives the overflow a color. An image does not work:

html {     background: url(image.png); } 

How can I put an image in the html overflow?

like image 702
Randomblue Avatar asked May 14 '16 15:05

Randomblue


2 Answers

You can achieve this result on Safari (I failed to achieve this on other browsers).

HTML

<html>   <body>     <div class="body-wrapper">       Content goes here     </div>   </body> </html> 

CSS

/* --- Reset rubber effect on the 'html' tag --- */ html {     overflow: hidden;     height: 100%; }  body {     height: 100%;     overflow: auto; } /* ------------ end reset ------------ */  html {     background-color: white;     background-image: url("http://www.freebordersandclipart.com/images/EasterEggThree.png");     background-repeat: no-repeat;     background-size: 6%;     background-attachment: fixed;     background-position: 50% 10px; }  .body-wrapper {     background-color: white; } 

You must remove the default rubber effect on the html element (since you can't put graphic on the html parent element - there isn't an html parent). body has got a rubber effect and transparent background - lack of background is important since the rubber effect expand this colour and can overlap the Easter egg graphic. .body-wrapper has got background colour to hide the Easter egg.

Here you can see the effect (on the desktop it works only on Safari).

like image 153
Everettss Avatar answered Sep 27 '22 18:09

Everettss


There is a cross-browser touch-friendly solution that every front-end developer should know: iScroll by Matteo Spinelli (http://cubiq.org/iscroll-5).

He created a cross-browser simulation of the rubber band effect, that is fully stylable. iScroll can be used for this purpose (as well as many others). I personally use it mostly to create overflow on divs in mobile devices, as they are normally not allowed.

Here is an old-school easter egg using a background image on the #wrapper: http://codepen.io/anon/pen/OXMmgr... JIPPY....JIPPY JIPPY JIPPY!

PS. If you want something that works on 'regular' scroll-wheel scrolling, try this repo: https://github.com/ftlabs/ftscroller

like image 31
JoostS Avatar answered Sep 27 '22 18:09

JoostS