Code Monkey home page Code Monkey logo

scroll-restoration-demos's Introduction

history.scrollRestoration ALSO Affects External Links

Typically, you want set history.scrollRestoration to manual to allow custom transitions.

This API applies to the current entry, which means the scroll state will also NOT be restored when navigating back from external links.

Scroll Restoration Happens AFTER popstate

This means you can always get current scroll position on popstate, but probably not in async callbacks (e.g. Promises). The actual restoration timing is implementation-related: It takes one animation frame in Chrome, and several more in Safari.

Get Scroll Position

To get scroll position, there's many APIs with different compatibility issues such as:

  • window.scrollY
  • window.pageYOffset
  • document.body.scrollTop
  • document.documentElement.scrollTop
  • document.scrollingElement.scrollTop

Here we don't examine these APIs one by one, here's a demo to test with:

NEVER Set scrollY or pageYOffset

Always use scrollTo to scroll your page. Through scrollY and pageYOffset are NOT readonly, which means they can be set, they WON'T change anymore once assigned. Take care!

scroll event not fired on UIWebview

Typically scroll event will be fired on scroll restoration. Whereas for iOS UIWebview-based browsers no scroll event will be fired. Try UC browser, Baidubox browser.

scroll-restoration-demos's People

Contributors

harttle avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

win-22

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.