.js ScrollTop to div or section tag
I have the following script that allows me to add an anchor-link with a
.class attached to my HTML document, which would then scroll the user to a
position on the webpage when clicked on.
HTML:
<li class="about-scroll">About</li>
JavaScript:
$('.about-scroll').click(function () {
$('body,html').animate({
scrollTop: 646
}, 1600);
return false;
});
This works fine, however, as the content isn't always static (drop-down
accordions, a responsive layout etc.), how would I be able to scroll to a
specific #div or section tag rather than a numeric value on the page?
Example:
<div class="about">
<h3>About</h3>
...
...
...
</div> <!-- end .about -->
No comments:
Post a Comment