Using scrollTo and localScroll to navigated around a page and need to identify which link was clicked for use in a callback function. I’ve dug around the source of each and am unable to understand how to extract it.
What I’ve found for sure is that $(this) refers to the body element in its entirety. Thanks for your help!
Here’s my function:
$('nav').localScroll({
duration: 500,
easing:'easeOutSine',
axis:'xy',
onAfter: function(){
/* This is where I need to identify the anchor that was clicked*/
var test = $(this);
console.log(test);
}
});
HTML:
<nav>
<ul>
<li><a href="#one" class="active">One</a></li>
<li><a href="#two">Two</a></li>
<li><a href="#three">Three</a></li>
<li><a href="#four">Four</a></li>
<li><a href="#five">Five</a></li>
<li><a href="#six">Six</a></li>
</ul>
</nav>
With enabled
hashoption this could be useful: JQuery > ScrollTo > highlighting the item that was scrolled to.Other solution is adding another
clickevent to all links and setting variable/attribute which you could read later insideonAftercallback.