peachananr / purejs-onepage-scroll

The javascript version of the infamous jQuery One Page Scroll without relying on jQuery.
http://peachananr.github.io/purejs-onepage-scroll/demo/purejs_onepage_scroll_demo.html
GNU General Public License v2.0
770 stars 180 forks source link

Uncaught TypeError: Cannot read properties of null (reading 'dataset') #28

Open stuthemoo opened 2 hours ago

stuthemoo commented 2 hours ago

Sometimes on page load I get this error and I cannot scroll to the next section

stuthemoo commented 2 hours ago

Seems to be relateed to the loop option. If it's true then looping back to the first section will make the url hash 1 more than the total rater than setting it back to #1. If you then reload it looks for a section that doesn't exist and breaks.

stuthemoo commented 2 hours ago

For a quick fix change line 83 from: if(window.location.hash != "" && window.location.hash != "#1") { to: if(window.location.hash != "" && window.location.hash != "#1" && document.querySelector(settings.sectionContainer + "[data-index='" + (window.location.hash.replace("#", "")) + "']")) { https://github.com/peachananr/purejs-onepage-scroll/blob/b86163211c9e40019a2223bf85f0ad02aa0cf57f/onepagescroll.js#L83