Is my slide-to-anchor jQuery routine a correct use of JavaScript, or is there a better way?
Posted
by Stuart Robson
on Stack Overflow
See other posts from Stack Overflow
or by Stuart Robson
Published on 2010-03-13T19:52:34Z
Indexed on
2010/03/13
20:15 UTC
Read the original article
Hit count: 279
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?
© Stack Overflow or respective owner