简体   繁体   中英

Scroll to next div jQuery

I´m working on this page

As you can see, in the bottom-middle there is an arrow that right now I haven´t been able to make it scroll to the next section.

You can see the next project by normal scroll but I want to activate it also on the arrow .

This is the markup:

<a id="arrow-down" href="#" onclick="javascript:void(0);"></a>

This is what I have tried:

    $('#arrow-down').on('click', function () {
        var ele = $(this).closest("div").find(".project.skrollable");
        // this will search within the section
        $("html, body").animate({
             scrollTop: $(ele).offset().top
        }, 100);
        return false;
    });

Any ideas what I´m doing wrong? or how can I achieve it?

Try this:

<a id="btn" href="#" ></a>

Give the div Id to <a> href

$window = $(window);
        $window.scroll(function () {
            if ($window.scrollTop() >= 0 && $window.scrollTop() < 1000) {
                $("#btn").attr("href", "#div1");
            } else if ($window.scrollTop() >= 1000 && $window.scrollTop() < 2000) {
                $("#btn").attr("href", "#div2");
            } else if ($window.scrollTop() >= 2000 && $window.scrollTop() < 3000) {
                $("#btn").attr("href", "#div3");
            } else if ($window.scrollTop() >= 3000 && $window.scrollTop() < 4000) {
                $("#btn").attr("href", "#div4");
            } else if ($window.scrollTop() >= 4000) {
                $("#btn").attr("href", "#div5");
            }
        });


        $("#btn").click(function () {

            var div = $("#btn")[0].hash;
            var lastChar = div[div.length - 1];
            lastChar++;
            $("#btn").attr("href", "#div" + lastChar + "");
        });

DEMO

i found you that, you added required JS at wrong place. (currently it's on line: 562 according to source view)

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript" src="http://archcase.com/wp-content/themes/archcase/js/jquery.mousewheel.js"></script><!-- the mousewheel plugin -->
<script type="text/javascript" src="http://archcase.com/wp-content/themes/archcase/js/jquery.jscrollpane.min.js"></script><!-- the jScrollPane script -->
<script type="text/javascript" src="http://archcase.com/wp-content/themes/archcase/custom_templates_css/Mullion/js/skrollr.js"></script>
<script type="text/javascript" src="http://archcase.com/wp-content/themes/archcase/custom_templates_css/Mullion/js/plugin.js"></script>
<script type="text/javascript" src="http://archcase.com/wp-content/themes/archcase/custom_templates_css/Mullion/js/main.js"></script>

add these js includes to the top of page. it should be on line:60 at least.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM