Hey there! I'm currently facing an issue with jquery scrollTop. Whenever I navigate to the id #linkA and click it again, an unnecessary scroll is added. I'd like to prevent scrolling after clicking the link. Imagine these three paragraphs have a significant gap between each other.
Here's the HTML:
<ul>
<li><a href="#linkA"> Link A </a></li>
<li><a href="#linkB"> Link B </a></li>
</ul>
<p id="#linkA">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
<p id="#linkB">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
Jquery code:
$(document).ready(function() {
$('.a').click(function() {
$('body').animate({
scrollTop: $("#linkA").offset().top
}, 500);
return false;
});
$('.b').click(function() {
$('body').animate({
scrollTop: $("#linkB").offset().top
}, 500);
return false;
});
});
$(window).scroll(function() {
var windowTop = $(document).scrollTop();
if (windowTop > 0 && windowTop <= 200) {
// Parallaxing code goes here
}
});
Do you have any suggestions on how to disable scrollTop when a link is clicked? Appreciate your help!