2016-01-21 38 views
2

我有碼寫的,但我不知道該ifelse零件後放什麼「setFitToSection」選項的值。我想要做的 - 每當一個部分有「四」和「積極」類我想要禁用FitToSection選項fullpage.js。 Fullpage.js有一個我正在使用的setFitToSection布爾值。這是我到目前爲止,我還需要什麼?Fullpage.js - 設置基於如果一個div有一定的階級

$(document).ready(function() { 
    if ($('.four').hasClass('active') === true) { 
     $.fn.fullpage.setFitToSection(false); 
    } 
    else { 
     $.fn.fullpage.setFitToSection(true); 
    } 
}); 
+0

檢查'else'一部分,你有錯字,錯過了'if'。您可以簡單地使用它來代替這種情況。 '如果($( '四 ')。hasClass(' 激活')){} 其他 { }' –

回答

0

只需使用fullpage.js提供了回調,如afterLoadonLeave

$('#fullpage').fullpage({ 
    autoScrolling:false, 

    onLeave: function(index, nextIndex, direction) { 
     var destination = $('.fp-section').eq(nextIndex - 1); 

     if(destination.hasClass('four')){ 
      $.fn.fullpage.setFitToSection(false); 
      console.log("setting fitToSection off"); 
     }else{ 
      $.fn.fullpage.setFitToSection(true); 
      console.log("setting fitToSection on"); 
     } 
    } 
}); 

Example online

你不需要在這種情況下,因爲以檢查active類目的地部分將永遠擁有它。只要檢查它是否有four課程。

相同的腳本的一個較短的版本可以是:

$('#fullpage').fullpage({ 
    autoScrolling:false, 

    onLeave: function(index, nextIndex, direction) { 
     var destination = $('.fp-section').eq(nextIndex - 1); 
     $.fn.fullpage.setFitToSection(!destination.hasClass('four')); 
    } 
}); 
+0

啊,是我應該檢查這個類,更簡單。我插入了較短的版本,它工作,謝謝! – dsiglin

+0

我說得太快了@阿爾瓦羅。當我第一次進入「四」級的部分時,它仍然移動到該部分的底部。之後,它可以讓我在該部分內滾動,而不必適合部分。 – dsiglin

+0

然後,您需要在訪問「four'類的部分之前將其關閉。 – Alvaro

相關問題