Giter Club home page Giter Club logo

Comments (2)

adamreisnz avatar adamreisnz commented on July 20, 2024

I think this is a bug in Firefox. I've encountered a similar issue when trying to scroll to the top element of the page which was offset by a margin. Firefox doesn't seem to take the top margin into account for determining the document.body.scrollHeight, causing ngSmoothScroll to stop scrolling prematurely due to the comparison:

(window.innerHeight + currentLocation) >= document.body.scrollHeight

At the start of the animation, when you have scrolled down almost all the way of the page, this comparison will be triggered incorrectly, because the document body scroll height is too little, causing ngSmoothScroll to stop the animation before it even started.

In Chrome this problem does not occur, as the margin is added correctly to the document body scroll height.

See this fiddle to see the problem (open it in Firefox and Chrome) and notice how in Firefox the scroll height is reported as 1000px, which is exactly the element's height, but excludes the margin (and body padding):

https://jsfiddle.net/xvbaoakg/

You can work around this problem by either commenting out the comparison in the smooth scroll library, or avoiding to use margins on your elements and add a padder element with padding instead.

from ngsmoothscroll.

adamreisnz avatar adamreisnz commented on July 20, 2024

Actually, just found a proper fix for this problem. Instead of using document.body.scrollHeight, use this to determine the correct document height:

var docHeight = Math.max(
    Math.max(document.body.scrollHeight, document.documentElement.scrollHeight),
    Math.max(document.body.offsetHeight, document.documentElement.offsetHeight),
    Math.max(document.body.clientHeight, document.documentElement.clientHeight)
);

Updated fiddle: https://jsfiddle.net/xvbaoakg/1/

Will create a PR for this fix.

from ngsmoothscroll.

Related Issues (20)

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.