I have developed a simple link animation for scrolling. This link can be used to navigate to a section within the same page or an external URL. However, there are a couple of issues that I encountered with this implementation.
First Issue: When clicking on the button ("section 4"), there is a strange movement experienced. This inconsistency was the initial problem I faced.
Second Problem: If a user clicks on a button multiple times and then proceeds to click on another button, the scroll function does not work until the previous click action has completed:
The code snippet is as follows:
$(".links a").click(function () {
$("html, body").animate({
scrollTop: $($(this).attr("href")).offset().top
}, 1400)
})
.links {
width:600px;
position:fixed;
top:0;
padding:20px;
}
.links a {
display:inline-block;
padding:10px 20px;
border:1px solid #0094ff;
}
.section {
width:400px;
height:200px;
margin:300px auto 600px;
background-color:#0094ff;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="links">
<a href="#section1">Section 1</a>
<a href="#section2">Section 2</a>
<a href="#section3">Section 3</a>
<a href="#section4">Section 4</a>
<a href="http://google.com">External Link</a>
</div>
<div id="section1" class="section"></div>
<div id="section2" class="section"></div>
<div id="section3" class="section"></div>
<div id="section4" class="section"></div>
Note: Please refrain from suggesting any plugins, as I am keen on exploring Javascript further.