flesler / jquery.localScroll

Animated anchor navigation made easy with jQuery

Home Page:http://demos.flesler.com/jquery/localScroll/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

disable localScroll handlers once added?

jmires opened this issue · comments

Two issues in one day - I don't mean to be a pest!

Is it possible to disable localScroll after it's been added? As part of a responsive implementation, I'm activating localScroll only on wide screens, and just using regular anchor links on narrow screens. This works fine (I add localScroll based on a media query match when the page reaches a certain width) but is there a way to remove it if the browser is scaled down?

It seems like filter might work (basically filter out all the links) but I'm not sure of the filter syntax. Can I pass a jquery selector to filter? All I can find is that filter takes a "String or function filter to ignore some of the links" but I don't see any syntax examples or any use of filter on the demo pages.

Thanks!

The event name is customizable, being "click" the default. So you could pass:

$.localScroll({...., event:'click.localScroll',... });

And to clean it up:

$('*').unbind('click.localScroll');

Of course there are more optimal ways to clean it up but this is the simplest, you can improve it if you want.

Ah, of course! Thanks for pointing me in the right direction - I got this part working nicely.

@jmires would you mind posting an example of how you implemented this? I am looking to do almost the exact same thing! Thx!

@jessicaldale Sure, here's a simplified, commented example.

It's stripped down, as the actual implementation made use of waypoints to update the active nav item when the users scrolls the page, as well as localScroll features for adding the hash to the address bar, and scrolling properly if a user visits the URL with a hash.

In the process of stripping it down, I removed a lot of CSS - as a result, it's best to look at this in a modern browser.

Let me know if you have questions.

@jmires BRILLIANT! thanks for this! I am not seeing waypoints on this example?

@jessicaldale Yeah, sorry my comment was clear - the demo I made was stripped down, and I removed the waypoints stuff to make it easier to follow what's going on with the localScroll code. Would a version that includes waypoints be helpful?