I have a page template like this:
<div class="page-wrapper">
<header class="header-5">
<div class="container">
content
</div>
<div class="background"></div>
</header>
<section class="content-3">
<div class="row">
<div class="col-sm-8 col-sm-offset-2 text-center">
content
<a class="control-btn" href="#"> </a>
</div>
</div>
<div class="container">
When <a class="control-btn" href="#"> </a>
is clicked, I want it to scroll to the last <div class="container">
(the last line in the code snippet).
With this jQuery, it scrolls to the first div.container
(toward the top of the snippet):
$('.control-btn').on('click', function() {
$.scrollTo($(".container"), {
axis : 'y',
duration : 500
});
return false;
});
How can I get it to scroll to the next div.container
(the last one in my code example)?
Note: There are other div.container
elements further down -- this isn't the "last" one on the page.
$('.control-btn').on('click', function () {
var ele = $(this).closest("section").find(".container");
// this will search within the section
$("html, body").animate({
scrollTop: $(ele).offset().top
}, 100);
return false;
});
DEMO
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With