All Projects → dimitrinicolas → overflow-color

dimitrinicolas / overflow-color

Licence: MIT License
Automatically switch CSS html background-color to bring a smooth user experience

Programming Languages

javascript
184084 projects - #8 most used programming language
HTML
75241 projects

Projects that are alternatives of or similar to overflow-color

front-end-interview
collection of interviewed questions
Stars: ✭ 54 (+35%)
Mutual labels:  front-end
react-native-bounceable
Animate and bounce any component with RNBounceable for React Native
Stars: ✭ 26 (-35%)
Mutual labels:  front-end
single-spa.js.org
single-spa.js.org/
Stars: ✭ 84 (+110%)
Mutual labels:  front-end
react-native-imaged-carousel-card
Fully customizable & Lovely Imaged Carousel Card for React Native
Stars: ✭ 70 (+75%)
Mutual labels:  front-end
baidu-ife
百度前端技术学院 2017 学习
Stars: ✭ 21 (-47.5%)
Mutual labels:  front-end
soloalert
A customizable lightweight Alert Library with Material UI and awesome features.
Stars: ✭ 18 (-55%)
Mutual labels:  front-end
modern-fluid-typography-editor
Modern fluid typography editor
Stars: ✭ 222 (+455%)
Mutual labels:  front-end
inview
Detect when element scrolled to view
Stars: ✭ 35 (-12.5%)
Mutual labels:  scrolling
fay-react-redux-example
No description or website provided.
Stars: ✭ 14 (-65%)
Mutual labels:  front-end
ng-scrollable
Superamazing scrollbars for AngularJS
Stars: ✭ 58 (+45%)
Mutual labels:  scrolling
volx-recyclerview-fast-scroll
An easy to use implementation for fast scroll recyclerview
Stars: ✭ 34 (-15%)
Mutual labels:  scrolling
bootstrap-gulp-starter-template
Bootstrap 4 + Gulp 4 + Panini for improve front-end development workflow
Stars: ✭ 67 (+67.5%)
Mutual labels:  front-end
vsc html5 boilerplate
This is a Visual Studio Code snippet extension for generating HTML 5 boilerplate code
Stars: ✭ 32 (-20%)
Mutual labels:  front-end
challenge-charlie
Frontend code challenge
Stars: ✭ 71 (+77.5%)
Mutual labels:  front-end
BFEdevSolutions
Solutions to problems that I solved on bigfrontend.dev
Stars: ✭ 21 (-47.5%)
Mutual labels:  front-end
react-cartographer
Generic component for displaying Yahoo / Google / Bing maps.
Stars: ✭ 82 (+105%)
Mutual labels:  front-end
hackernews-clone
HackerNews clone built with Angular 5 using the official firebase HackerNews API
Stars: ✭ 14 (-65%)
Mutual labels:  front-end
reactjs-portfolio
Welcome to my portfolio react.js repository page.
Stars: ✭ 109 (+172.5%)
Mutual labels:  front-end
scrollparent.js
A function to get the scrolling parent of an html element.
Stars: ✭ 51 (+27.5%)
Mutual labels:  scrolling
frontendQuickbytes
A repo containing real life frontend challenges which you can use to practice frontend!
Stars: ✭ 129 (+222.5%)
Mutual labels:  front-end

overflow-color Build Status 0 dependency npm bundle size (minified + gzip)

Demo

Try it on your smartphone or with a trackpad on MacOS: git.io/overflow (https://dimitrinicolas.github.io/overflow-color/)

A simple script that automatically switches CSS html background-color according to scroll position.

This package is on npm

npm i overflow-color

Usage

You simply must add the browser minified script dist/overflow-color.umd.min.js and the two attributes data-oc-top and data-oc-bottom to your body tag.

<body data-oc-top="red" data-oc-bottom="blue">
    <!-- ... -->
    <script src="dist/overflow-color.umd.min.js" async></script>
</body>

You can use the shortcut data-oc by separating the two values with a comma.

<body data-oc="red,blue">

With a module bundler

You can import this package with a simple require or import.

require('overflow-color');
// with ES6+
import 'overflow-color';

You don't have anything else to do, the script is automatically launched when the DOM content is loaded.

Manually re-check scroll position

When you update body's overflow color attribute or make a huge change to the DOM (e.g. changing page with Angular) and that the vertical scroll position stayed at the top, the new document height may be smaller than the previous one, and overflow-color should set the overflow color to the bottom one, but it has not be called by scroll event. In this specific case, you can use the default exported function updateOverflowColor:

import updateOverflowColor from 'overflow-color';

/** Change DOM or body's overflow color attribute */

updateOverflowColor();

CSS tricks, Behind the Scenes

This library will wrap all the body content inside a <div data-oc-wrap>. Then it set to the wrapper the same background as the body, and set body's background to transparent.

Add the data-oc-outside attribute to any body's immediate children that you don't want to be included into this wrap element at DOM content load.

when the document is loaded:

<!doctype html>
<head>
    <!-- ... -->
    <style>
        /* your style */
        body {
            background: lightgrey;
        }
    </style>
    <style>
        /* style added by the script */
        html { background: blue; }
    </style>
</head>
<body data-oc="red,blue" style="background: transparent; /* style added by the script */ ">
    <!-- wrapper added by the script -->
    <div data-oc-wrap style="background: lightgrey;">
        <!-- ... your body's childs -->
        <script src="dist/overflow-color.umd.min.js" async></script>
    </div>
</body>

You can read the Designer News discussion about the different tried tricks.

Browsers compatibility

I successfully tested this library, on:
Mac OS Mojave: Safari v11, Google Chrome v70 and Opera v51
iOS 11: Safari, Google Chrome v68, Firefox 12 and Microsoft Edge v42

Unfortunately, Firefox on MacOS and Opera Mini on iOS doesn't show the over-scroll color even without this library.

This library pass an E2E test through Chrome with Cypress.

Build

Compile with Rollup:

npm run build

Build and test with Cypress:

npm test

License

This project is licensed under the MIT license.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].