I am trying to do a down arrow that will move through anchors by order (one by one) on click with jquery. So far i only manage to move them at once.
var targets = new Array();
$(".jump").each(function() {
targets.push($(this).attr('id'));
});
$("#clickme").click(function() {
for (var i = 0; i < targets.length; i++) {
if (i + 1 >= targets[i]) {
$("html, body").animate({
scrollTop: $('#' + targets[i]).offset().top
}, 1000);
}
}
});
p {
padding-top: 100px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a style="cursor: pointer;" id="clickme">Click Here</a>
<a class="jump" id="1"></a>
<p>Lorem ipsum dolor sit amet...</p>
<a class="jump" id="2"></a>
<p>Lorem ipsum dolor sit amet...</p>
<a class="jump" id="3"></a>
<p>Lorem ipsum dolor sit amet...</p>
My code or algorithm could be wrong. I am open to alternatives with jQuery.