Giter Site home page Giter Site logo

scroll-restoration-proposal's Introduction

Scroll Restoration API

This API is now part of WhatWG HTML spec. It has been implemented in Chrome since version 46 and is expected to be in Firefox from version 46.

This repository hosts the early draft spec for scroll restoration API which aims to make it possible for web authors to disable the automatic scroll restoration in their web apps. This draft is now out-dated and superseded by the official spec .

There are also tests covering the spec.

References

scroll-restoration-proposal's People

Contributors

majido avatar mathiasbynens avatar rbyers avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

scroll-restoration-proposal's Issues

Impact on restoring form state

Should cancelling restorestate prevent restoration of form state too? If so, then can/should we expose the raw form state in the event somehow? If not, what do we do if we decide we want to add such support later?

prevent* methods on Event considered wierd

From Olli Pettay:

It is unusual Events to have methods like preventScrollRestoration() or preventScaleRestoration() ( ServiceWorker events are weird special cases.)
Usually events just carry data/state and information that something will happen unless preventDefault() is called, or information that something just happened (in which case preventDefault() doesn't do anything).
Using the same event to prevent scroll restoration and scale restoration sounds is like merging two features to one event. What if there is no scaling restoration involved and preventScaleRestoration() is called? what should happen?

Is there some reason to not dispatch separate events for different features:
"restoreScrollPosition", "restoreScale". I'd argue that usually pages want to prevent scroll position, but preventing scale restoration can be rather annoying for user at least in case of cross-page navigations.

I'm certainly not strongly against the model defined in event-based-api.md, but just thinking also other options.

Expose recorded scroll position

It is useful for applications to be able to read the recorded scroll position even if they are implementing their own custom scroll restoration. It allows them to no longer record the scroll position themselves. For example an infinite-scroller page can disable scroll restoration but use the recorded scroll position to load enough content to render.

Notes:

  • The main advantage is that it eliminates the need for web apps to implement logic for recording scroll position themselves. However once scroll restoration is disabled, recording scroll position becomes quite simple so this may not be as valuable.
  • Some user-agents do restore iframe scroll positions. Exposing these iframe scroll position may add too much complexity that is not worth the benefit.

When is the 'restorestate' event fired?

From Jonas Sicking:

When we designed the pushState() API we ran into problems with a
similar event which caused some significant problems and required a
last-minute redesign. The resulting design for pushState() is that the
'popstate' event does not fire when the user does a session-history
traversal that navigates between Documents. There simply was no good
time to fire such an event.

If we fired 'popstate' before the 'load' event, then the <script

which added the event listener might not have loaded yet. If we fired
'popstate' after the 'load' event then the page didn't know what state
to render the page in until the 'load' event fired, which results in
crappy UX.

Instead we made the current state available through history.state, and
then 'popstate' only fires for sessionhistory transitions within the
same Document, i.e. when history.state changes.

So when does 'restorestate' fire? Does it fire before or after 'load'?
Keep in mind that browsers start restoring the scroll state long
before 'load' but doesn't load all <script>s until 'load' has been
fired.

Consider supporting disabling scale restoration

Some browsers (e.g., Chrome Android, IE Mobile) restore scale as well as scroll position. We should be able to allow developers to disable this as well.

Note that most mobile web-apps disable user scaling altogether which is why this is not as bad as scroll restoration problem

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.