Comments (2)
I notice this problem for years. I decided to fix it. So i did it in this way:
First of all, use unminified version of js, after fixing minify it again.
Replace "proto.onUnload = function" function with this function:
proto.onVisibilityChange = function() {
if (!this.scrollPage) return;
if (this.scrollPage.top === 0) return;
if (document.visibilityState === 'visible') return;
// calculate where scroll position would be on refresh
let scrollY = window.scrollY - this.scrollPage.top + this.top;
// disable scroll event before setting scroll #679
this.destroyHistory();
scrollTo(0, scrollY);
};
also add this function below this function:
proto.bindVisibilityChangeEvent = function(isBind) {
let addRemove = isBind ? 'addEventListener' : 'removeEventListener';
window[addRemove]('visibilitychange', this.onVisibilityChange);
};
then find "proto.createHistoryAppend = function()" function, replace it this one:
proto.createHistoryAppend = function() {
this.updateMeasurements();
this.updateScroller();
// array of scroll positions of appended pages
this.scrollPages = [
// first page
{
top: 0,
path: location.href,
title: document.title,
},
];
this.scrollPage = this.scrollPages[0];
// events
this.scrollHistoryHandler = this.onScrollHistory.bind( this );
this.visibilityChangeHandler = this.onVisibilityChange.bind(this);
this.scroller.addEventListener( 'scroll', this.scrollHistoryHandler );
this.on( 'append', this.onAppendHistory );
this.bindHistoryAppendEvents( true );
this.bindVisibilityChangeEvent(true);
};
finally, replace "proto.bindHistoryAppendEvents = function(isBind)" function with this one:
proto.bindHistoryAppendEvents = function(isBind) {
let addRemove = isBind ? 'addEventListener' : 'removeEventListener';
this.scroller[addRemove]('scroll', this.scrollHistoryHandler);
this.bindVisibilityChangeEvent(isBind);
};
I did not encounter any problems when I made changes this way. If you encounter any problems, I would appreciate it if you let me know.
from infinite-scroll.
I made a small fix because itβs urgent, it might be useful to someone. Do not judge strictly.
The "beforeunload" event seems to correctly calc the scrolling, but the scrolling itself is visible - unfortunately.
Event "pagehide" - failed to make friends with Safari, i.e. For the Chromium line everything is great, but in Safari the scroll calculation fails the first time you go back.
I've settled on "visibilitychange" for now, no critical bugs seem to be visible, currently browser support is 95%.
Instead of lines:
window[ addRemove ]( 'unload', this.unloadHandler );
Fix:
var _this = this;
function fix(e) {
if (document.visibilityState === "hidden") {
_this.unloadHandler.call(document, e);
}
}
document[ addRemove ]( 'visibilitychange', fix);
from infinite-scroll.
Related Issues (20)
- infinite-scroll with websockets
- tile HOT 1
- Items shown and total items under view more button HOT 3
- Fackbook hack
- Infinite scroll + JSON
- Cloudflare mirage data-cfsrc lazy load conflict
- my tumblr theme's images not loading after page 1 (Safari only) - Infinite scroll & load more issue HOT 3
- Feature - Combination with Pagination - Load and Scroll to specific Page
- Page Link Issue
- Card Columns Not Working
- Web App For Iqama status
- Infinite-scroll and Joomla
- View Transitions
- Infinite Scroll + Masonry works only sometimes, sometimes it bugs HOT 1
- prefill loads data endlessly when container has display:none HOT 2
- Rating of a topic and infinite scroll HOT 20
- Want to create website tool for BCBS Prefix List HOT 3
- Is there an option to load the next x or all pages without scrolling?
- After product screening, Infinite scroll no longer works HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from infinite-scroll.