bendc / anchor-scroll Goto Github PK
View Code? Open in Web Editor NEWSmooth and lightweight anchor scrolling library
License: MIT License
Smooth and lightweight anchor scrolling library
License: MIT License
Unfortunately no Javascript error showing up in console.
Obviously more of a user error scenario here, but if you attempt to link to an ID that is not on the page, you get the following error: Uncaught TypeError: Cannot read property 'getBoundingClientRect' of null
What do you think about not attempting to move anywhere at that point if you can't find the selector?
Also, I'd like to suggest adding a single # with no ID should scroll up to the top of the page as a native # would.
cant hurt - simple, focused modules such as this are often highly depended on
You could get rid of the UA sniffing and go for a more robust, feature-testing-based approach. Here’s how that could work: https://github.com/mathiasbynens/jquery-smooth-scrolling/blob/fba27f86a6b3a8788d1c1b3aa94a951eb9f087dc/jquery.smoothscroll.js#L4-L21
Here’s a simpler version by @dperini: https://gist.github.com/dperini/ac3d921d6a08f10fd10e
Update in 2015: use document.scrollingElement
when available
This repository seems to be unmaintained, as there are 5 open pull requests with no recent activity.
Should this repo be forked, and switched maintainers?
By the way, great work @bendc! Thanks!
Wanted to see how you felt about the ability to use public methods to call this library on arbitrary content that may not have a click handler associated with it.
AnchorScroll(document.querySelector('#my-content'));
:(
Looks like the code is running through some kind of transpilation step, because the fat arrow functions are missing from the .min
file, and the const
declarations are converted to var
. is it possible that the minifier is smart enough to remove them?
Anyways, the Map
object and the Array.from
method - both of which are part of the ES6 spec - make an appearance in the .min
file. Perhaps this should be noted in the README?
Have a considerable junk on scrolling all the way down to the bottom of the page.
I found out that scrolling to an anchor works wonderfully, however breaking the browser's back button's functionality (Chromium, Firefox, Safari Mobile).
After commenting out the below, the back button works, however not scrolling smoothly.
I was trying onpopstate and different onpushstate variants to have it scroll smoothly to the top again, upon clicking the back button, but wasn't able to do so. If you have an idea, I'd appreciate it.
const complete = (hash, coordinates) => {
//history.pushState(null, null, hash);
root.scrollTop = coordinates.get("start") + coordinates.get("delta");
};
const attachHandler = (links, index) => {
const link = links.item(index);
link.addEventListener("click", event => {
//event.preventDefault();
scroll(link);
});
In pages where there is no anchors:
Uncaught TypeError: Cannot read property 'addEventListener' of null
In Chrome
I guess, it needs a if (link) or if (links) somewhere https://github.com/bendc/anchor-scroll/blob/master/scroll.js#L57
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.