Scroll to the next div using jQuery

I have a page template as follows:

<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 the button is pressed <a class="control-btn" href="#"> </a>, I want it to scroll to the last <div class="container">(last line in the code snippet).

With this jQuery, it scrolls to the first div.container(at the top of the snippet):

 $('.control-btn').on('click', function() {
        $.scrollTo($(".container"), {
            axis : 'y',
            duration : 500
        });
        return false;
    });

How can I make it go to the next div.container (last in my code example)?

Note. The remaining elements div.containerare located below - this is not the "last" on the page.

+4
source share
1 answer
$('.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

+6
source

Source: https://habr.com/ru/post/1544619/


All Articles