thesmart / jquery-scrollspy Goto Github PK
View Code? Open in Web Editor NEWA ScrollSpy library for detecting enter/exit of elements in the viewport when the user scrolls
License: Other
A ScrollSpy library for detecting enter/exit of elements in the viewport when the user scrolls
License: Other
You have a boo-boo in the example file.
You need to change:
<script src="../scroll-spy.js"></script>
to:
<script src="../scrollspy.js"></script>
Not a big deal. Any good developer can detect and fix this on his own.
Hi
I am using the following html:
`
and using the scrollSpy plugin as follows:
`
$('#section2').on('scrollSpy:enter', function() {
alert("scrolled in");
});
$('#section2').on('scrollSpy:exit', function() {
alert("scrolled out");
});
$('#section2').scrollSpy();
`
When the page loads, even though #section2 is not visible the alert is shown by the browser. How can I avoid this?
Also, if increase the height to 101% this issue is not occuring.
AMD support??
Hello
I got the problem. All Selectors is fired Enter in the first loading time.
can you tell me how to fix it?
Thanks
I am developing a jQuery Mobile 1.4 multi-page mobile app, also using ScrollSpy. It lists items on a page, and when it is (supposedly) seen by the user, it pings a server. You can click on the list item to go to a detail view page. When I navigate back to the list view, ScrollSpy doesn't spy any more.
As a fix, I had to add this to the scrollspy source code:
$.clearScrollSpy = function()
{
jWindow = $( window );
elements = [];
elementsInView = [];
isSpying = false;
ticks = 0;
offset = {
top : 0,
right : 0,
bottom : 0,
left : 0,
};
return this;
};
It sets the object properties to their default values. Then call it like this after navigating back to the list view page: $.clearScrollSpy().scrollSpy( '.coupon_tracker' );
. I use the class "coupon_tracker" to identify HTML elements to be tracked.
Scrollspy works fine, but generally I need to modernize it.
As you may already know, jQuery Plugins repository has gone to “read only” mode and thus the authors of plugins are told to create modules for npm out of their plugins.
Consider creating a jQuery ScrollSpy module for npm.
Hi - great lib nice that materialize have started to use it. So I found you as I wanted an event for when the item is in the middle of the viewport. It almost feels faster to do it myself but would prefer to levarage and already in use lib ..thanks
Is there a way to set an offset of the element before/after entering the screen?
I am having trouble with spying on elements which are shorter than the window height and the next element enters - then the next element takes precendence over the element that was already in screen and didn't exit
By default, Google Chrome remembers your scrolling position when you reload the page. When using this plugin to create a fixed navbar, this causes some issues: the page loads at a point where the navbar should be visible, but it isn't.
Is there a way around this? Thanks.
thanks for this great plugin. I just tested it, but unfortunately it doesn't work on content which is within a div with style overflow-y: scroll;
maybe because the viewport sit's on window? any idea how to get this working??
Great and simple plugin :D
here is my case, i have one class at first, then i loaded new element, but the scrollspy not updated. My new element didnt counted as scrollspy element.
Any idea how to get this working?
Thanks in advance
The lines of code using attribute selectors to match the id do not work with the latest jQuery:
$('a[href=#' + visible[0].attr('id') + ']')
In my case, the error thrown is:
Error: Syntax error, unrecognized expression: a[href=#objective]
Simply changing the code to match the following correctly using "
fixes this:
$('a[href="#' + visible[0].attr('id') + '"]')
I am happy to raise a PR to fix this as I feel it is quite important to address since Materialise CSS uses your plugin.
@thesmart I have added this package to my package.json
file
"dependencies": {
...
"jquery-scrollspy": "https://github.com/thesmart/jquery-scrollspy.git"
...
}
when I run npm install
there is an error npm ERR! premature close
and this error because the package doesn't have a package.json
file name, would you please add it ?
Hi there. I'm using both scroll-to functions and scrollSpy in a current project, and have noticed they are of course incompatible.
Because scrollSpy listens to window scroll, and scroll-to anchors cause the window to scroll, weird jumping happens, etc. I'm aware there's a throttle, and keeping scrolls well within the throttle interval has prevent most weird stuff, but there are still edge cases that cause weird effects.
Is there currently a way to stop scrollSpy from listening for a set period of time? Would be really useful to be able to setTimeout some var to stop scrollSpy listening while scroll-to stuff is happening.
Eg:
scrollSpyWatching = false;
setTimeout(function() { scrollSpyWatching = true}, 500);
I'm using the jquery.on method with the scrollSpy:enter/:exit event, and the plugin is not detecting all of the divs I have it looking for.
I have the plugin looking for divs with specific classes, then applying a class to an SVG dot navigator to show the current section scrolled to. The functionality is a bit finicky, with sections not properly being detected, classes not being applied, etc. I have checked my code and it works fine, but the issue is that it's hooked on to the custom event.
The entire viewport of the browser is currently used as the field; elements that enter this area have "entered" to use the terminology of this library.
I'm in need of offsets here - I would like to say that elements only enter when they've been scrolled half way up the viewport. This is not possible with the current design of code, and would probably need a bit of refactoring.
Preferably this would be something you could define in the options when calling the scrollSpy() method.
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.