Ich musste etwas ähnliches tun, aber mit etwas mehr Flexibilität. Und es war wichtig, Abschnitte oben zu aktivieren, ohne den Inhalt der aktuellen Seite zu verschieben.
Ich habe gerade angefangen, FullPage.js
zu verwenden, also habe ich keine Probleme mit anderen Plugin-Funktionen versucht. Aber ich teile das Ergebnis hier.
Es ist ein wenig kompliziert, aber es tut was ich brauche! Beispiele am Ende ...
Ich hatte zwei Linien von FullPage.js
Plugin zu ändern:
function moveSectionUp(){
var prev = $(SECTION_ACTIVE_SEL).prevAll(SECTION_SEL + ':first'); // <--- THIS
// var prev = $(SECTION_ACTIVE_SEL).prev(SECTION_SEL); // <--- INSTEAD OF THIS
Und
function moveSectionDown(){
var next = $(SECTION_ACTIVE_SEL).nextAll(SECTION_SEL + ':first'); // <--- THIS
//var next = $(SECTION_ACTIVE_SEL).next(SECTION_SEL); // <--- INSTEAD OF THIS
Und das sind die Funktionen hinzugefügt:
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;
}
Die Hauptanwendung ist dies:
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);
}
});
Und init und stellen Sie Ihre Logik auf 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
Dank! Dies löste ein ähnliches Problem für mich! – andreaslangsays