Is my slide-to-anchor jQuery routine a correct use of JavaScript, or is there a better way?
- by Stuart Robson
I'm currently working on a project with a one page design that'll slide up and down between sections on an <a href> link...
Currently, i have it written as follows:
<ul>
<li><a href="javascript:void(0)" onClick="goToByScroll('top')">home</a></li>
<li><a href="javascript:void(0)" onClick="goToByScroll('artistsmaterials')">artist's materials</a></li>
<li><a href="javascript:void(0)" onClick="goToByScroll('pictureframing')">picture framing</a></li>
<li><a href="javascript:void(0)" onClick="goToByScroll('gallery')">gallery</a></li>
<li><a href="javascript:void(0)" onClick="goToByScroll('contactus')">contact us</a></li>
</ul>
...with the most relevant portion being the links:
<a href="javascript:void(0)" onClick="goToByScroll('contactus')">
Then in a .js file I have:
function goToByScroll(id){
$('html,body').animate({scrollTop: $("#"+id).offset().top},'slow');
}
Is this ok? Or should this be done a different way?