alvarotrigo / alvarotrigo/fullPage.js

If selected sections are not sequential the plugin wont work with scroll or arrows

未關閉
#1,913 3 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
主要語言
JavaScript
星號
35.4k
分支
7.1k
PR 合併指標
30 天內沒有已合併 PR

描述

Hey there! First of all, thanks for the great plugin! But I'm now having some issues that are making me rip my hair off..

I'm attempting to create sections that are visible while on desktop whereas others while on mobile.
They are alternated with different classes (mobile and desktop), if I pass the ".desktop" selector to the sectionSelector it doesn't work.
- Shouldn't it just seamlessly use the array created by the selector used even though there might be alternated sections?

I've tried a workaround by selecting all sections and shifting the index to the one I'm interested in the specified device width "onleave" by using moveTo method. But although it works with the arrows, it doesn't work with scroll without glitches and some going back and forth unintentionally.

``` javascript
var device = 'desktop',
deviceSelector = '.'+device,
allSelector = '.section',
$allBlocks = $(allSelector),
$deviceBlocks = $(deviceSelector)
;

var indexMap = {};
var indexDevice = 0;

$allBlocks.each(function(indexAll) {
if (this == $deviceBlocks[indexDevice]) {
indexMap[indexAll+1] = indexDevice;
indexDevice++;
}
});

function shiftIndex(nextIndex, direction) {
if (direction == 'down') {
var upper = nextIndex;

while(upper < $allBlocks.length) {
if (indexMap[++upper] !== undefined) {
return upper;
}
}
return undefined;

} else {
var lower = nextIndex;

while(lower > -1) {
if (indexMap[--lower] !== undefined) {
return lower;
}
}
return undefined;
}
}

$('#fullpage').fullpage({
sectionSelector: allSelector,
scrollingSpeed: 1000,
keyboardScrolling: true,
navigation: true,
animateAnchor: true,
easingcss3: 'ease',

onLeave: function(index, nextIndex, direction){
if (indexMap[nextIndex] === undefined) {
var newIndex = shiftIndex(nextIndex, direction);
if (newIndex) {
$.fn.fullpage.moveTo(newIndex);
}
return false;
}
}
});
```
- Shouldn't it just work exactly the same for the different ways of interacting?

Any help on the issue would be much appreciated. Thanks again! ;)

貢獻指南

開啟貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。