peachananr / onepage-scroll

Create an Apple-like one page scroller website (iPhone 5S website) with One Page Scroll plugin
http://peachananr.github.io/onepage-scroll/Demo/demo.html
9.54k stars 2.07k forks source link

scroll to section 2 when click button #323

Closed helga-hai closed 5 years ago

helga-hai commented 6 years ago

How I make scroll to section 2 when click button (Section 1)?

$('.reload.btn').bind('click', function(){
     $(".main").moveTo(2);
});

This not work.

Veeraiyan-Tanke commented 6 years ago

Just call moveTo method on click function.

$(".anim-mouse").on("click", function() {

    var section_index = $('.main section.active').index();
    var section_length = $('.main section').length - 1;

    console.log(section_length);
    console.log(section_index);

    if (section_index == section_length) {
        $(".main").moveTo(0);
    }
    $('.main').moveDown();
});
helga-hai commented 6 years ago

Thank you very much for the answer. The scroll is happening. But when I press the button - the page reloads. Why is this happening?

Veeraiyan-Tanke commented 6 years ago

try this code

$('.reload.btn').bind('click', function(e){ $(".main").moveTo(2); e.preventdefault(); });

and if you using a tag then you need to provide the value like Link

helga-hai commented 6 years ago

Thanks. It worked.