2016-01-21 51 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

相关问题