inViewport falsely returns true
See original GitHub issueI attached verge.inViewport
to a scroll event to test this.
When I start scrolling I keep getting true
returned even if the element is not in the viewport. Only after I scroll past the desired element, false
is returned.
If I scroll back up past that element, it’s still true
.
Issue Analytics
- State:
- Created 7 years ago
- Comments:11 (6 by maintainers)
Top Results From Across the Web
determine if element is in viewport - return true / false
I am writing a small script to determine if an element is in the viewport... The problem that I am having is my...
Read more >@libshin/in-viewport - npm
In strict mode, the function inViewport returns true is the element is completely within the viewport. If a little part is off the...
Read more >Check If an Element is Visible in the Viewport in JavaScript
If the element is in the viewport, the function returns true . Otherwise, it returns false . Checking if an element is visible...
Read more >How to test if an element is in the viewport with vanilla ...
It returns an object with an element's height and width, as well as it's ... It returns true if it's in the viewport,...
Read more >inView | jQuery plugin to detect when DOM elements are in ...
Other plugins. How it Works. inView returns true or false on call instead of binding to an event, why you may wonder…
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Whoa I just figured out why the local differs from the codepen. Local has no doctype, If you add one then it works as expected! Discovered via S/O
So we either could warn about this in the readme and/or attempt a solution that works regardless.
@ryanve Well I’ve made this codepen using the link to load verge, and it’s working! But using the same link in a local .html file (or downloading verge.js and loading it locally) still behaves as before! I’m using Chrome 62.0.3202.62 64-bit on Windows 10.
So to reproduce it, copy the code below and save them as local files. Then run the .html file and you should run into the issue I’m having when you look at the Dev Tools console. These are the exact code I’m using locally (same as codepen but the html contains a script tag to load the javascript after loading verge):
index.html
script.js
When you scroll all the way down, these are the different console logs:
Codepen output (the correct output, only logs TRUE when the element is in view):
Local output (the incorrect output, only logs FALSE if you scroll pass the element, the rest of the time it logs TRUE):
I hope this helps.