Reputation: 8284
I'm using smoothscroll.js
on my website, that uses the 'click'
function.
It works great, problem is - it translates ALL links to toggle with the smooth scroll. This is problematic as I'm implemented small jQuery tabbed areas within a few of the vertical viewports.
Is there another function that acts similar to click that I can use interchangeably?
This is the smoothscroll.js
I'm loading on my site
Upvotes: 2
Views: 132
Reputation: 149714
Why not use my smoothScroll plugin? It allows you to define in which elements the links should scroll smoothly:
$('#smooth').smoothScroll(); // will only affect links in #smooth
You can also define the animation speed:
$('#smooth').smoothScroll(400); // scrolling takes 400ms
Here’s a demo: http://mathiasbynens.be/demo/smooth-scrolling
Upvotes: 2
Reputation: 11295
I see in your question that you've added the JQuery tag. The script you use doesn't seem to use JQuery, I've not read each line, but it looks pure JavaScript.
In the javascript file, replace the line:
var allLinks = document.getElementsByTagName('a');
By this JQuery selector:
var allLinks = $('a.fooClass');
And add class="fooClass"
to all the a tag you want to activate smooth scroll.
BTW: I found unacceptable that you have to edit the script to do so. If I was you I would look for a more solid JQuery plugin.
You might be interested by theses links:
Upvotes: 1
Reputation:
If you don't want all of the links in your page to have this behavior, then you need to modify and narrow down your selector. I'm guessing you're doing something like:
$('a').click(...
Instead, use a CSS class, or if it's only one item then use an id. Say you assign a CSS class to the tabbed areas links, then you'd do something like:
$('a.YourNewClass').click(...
I hope I am understanding your question correctly. If not, please let me know.
Upvotes: 1