문제

Ok, I am attempting to modify the existing fullpage.js plugin (https://github.com/alvarotrigo/fullPage.js/).

What I need is that when the user leaves each section, that section should automatically return back to the main slide of the section.

For example, using the my test site located here: (http://trouve.thinkatmosphere.com). If I am currently on the 'about' section and I navigate to the right and then leave the 'about' section and navigate down to the 'client' section when I return to the 'about' section I need it to be on the first slide of that section again.

How would I modify the following code to allow me to perform this:

$.fn.fullpage.moveToSlide = function (index, slide) {
  var destiny = '';
  if(isNaN(index)) {
    destiny = $('[data-anchor="'+index+'"]');
  } else {
    destiny = $('.section').eq( (index -1) );
  }
  if (isNaN(index) && slide !== 'undefined') {
    scrollPageAndSlide(index, slide);
  } else {
    if (destiny.length > 0) {
      scrollPage(destiny);
    }
  }
};`
도움이 되었습니까?

해결책

It can not be done with any option. You would need to modify the plugin for it, but not the function you are pointing out. That way the user would be redirected to the given section and slide. You need to make the movement in the background without the user's knowledge.

You would need to make the function scrollSlider public and call it from your own code (onLeave or afterLoad callbacks)

To make it public and therefore accesible from the initialization or any other external code, you would need to change the header of the function from this:

function scrollSlider(section, slide) {
    if (typeof slide != 'undefined') {
        var slides = section.find('.slides');
        var destiny = slides.find('[data-anchor="' + slide + '"]');
        if (!destiny.length) {
            destiny = slides.find('.slide').eq(slide);
        }

        landscapeScroll(slides, destiny);
    }
}

To this:

$.fn.fullpage.scrollSlider= function(section, slide){
  /// .... the same code as in the old function
}

Then, onLeave of the current section, you can call that function for that same section giving the value of 0 for the slide.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top