Мне нужно было сделать что-то подобное, но с большей гибкостью. И было важно включить разделы выше, не перемещая содержимое текущей страницы.
Я только начал использовать FullPage.js
, поэтому я не пытался создавать проблемы с другими функциями плагина. Но я разделяю результат здесь.
Это немного сложно, но он делает то, что мне нужно! Примеры в конце ...
мне пришлось изменить 2 строки FullPage.js
плагина:
function moveSectionUp(){
var prev = $(SECTION_ACTIVE_SEL).prevAll(SECTION_SEL + ':first'); // <--- THIS
// var prev = $(SECTION_ACTIVE_SEL).prev(SECTION_SEL); // <--- INSTEAD OF THIS
И
function moveSectionDown(){
var next = $(SECTION_ACTIVE_SEL).nextAll(SECTION_SEL + ':first'); // <--- THIS
//var next = $(SECTION_ACTIVE_SEL).next(SECTION_SEL); // <--- INSTEAD OF THIS
И эти функции добавлены:
fpInitSkipEl = function(funcSkipEl) {
if ($.isFunction(funcSkipEl)) {
var nextIndex = 0;
$('.section').each(function() {
nextIndex++;
$('a[href="#' + $(this).attr('data-anchor') + '"]').on('click', function() {
var dataAnchor = $(this).attr('href').toString().replace('#', '');
return funcSkipEl($('.section').index($('.section.active')) + 1, $('.section').index($('.section[data-anchor="' + dataAnchor + '"]')) + 1);
});
});
}
}
fpSkipEl = function(anchorsToSkip, index, nextIndex) {
//debugger;
$('.section').each(function() {
if (anchorsToSkip.indexOf($(this).attr('data-anchor')) > -1
&& (index==-1 || $(this).attr('data-anchor') != $('.section').eq(index - 1).attr('data-anchor'))
&& (nextIndex==-1 || $(this).attr('data-anchor') != $('.section').eq(nextIndex - 1).attr('data-anchor'))) {
$(this).css('display', 'none').removeClass('fp-section');
} else {
$(this).css('display', '').addClass('fp-section');
}
$.fn.fullpage.reBuild();
});
}
fpGetRealIndex = function(index) {
var realIndex = 0;
$('.section').each(function() {
realIndex++;
if ($(this).hasClass('fp-section')) index--;
if (index == 0) return false;
});
return realIndex;
}
Основное применение заключается в следующем:
fpInitSkipEl(function(index, nextIndex) {
// Fire on anchor Click
// You can play with index (the current section) and nextIndex (the next section)
if (index==1 && nextIndex==4) {
fpSkipEl(['page2', 'page3'], index, nextIndex);
}
});
И инициализации и установить логику afterLoad
$('#fullpage').fullpage({
anchors: ['page1', 'page2', 'page3', 'page4'],
afterLoad: function(anchorLink, index) {
// Get the real index with the hidden sections, oterwise index is relative to the visible sections.
var realIndex = fpGetRealIndex(index);
fpSkipEl([], -1, -1); // Show all sections
}
});
The simple working example on JSFiddle
A more complex example on JSFiddle
Спасибо! Это разрешило мне подобную проблему! – andreaslangsays