2015-11-23 73 views
0

我試圖在我的fullpage.js中實現afterLoad和onLeave多個事件的不同部分。但只有最後一個似乎有效,這裏有什麼可能是錯誤的?fullpage.js多個onLeave和afterLoad事件

如果我刪除最後一個,但第一個很好。所以它看起來像我把它們以錯誤的方式結合起來,所以一個禁用另一個。

$('#fullpage').fullpage({ 
     onLeave: function(index, nextIndex, direction) { 
      if (nextIndex == 3 || nextIndex == 1) { 
       $('.aboutme').hide("slide", { 
        direction: "left" 
       }, 200); 
      } 


     }, 
     afterLoad: function(anchorLink, index) { 
      if (index == 2) { 
       $('.aboutme').show("slide", { 
        direction: "left" 
       }, 200); 
      } 

     }, 

     onLeave: function(index, nextIndex, direction) { 

      if (nextIndex == 2) { 
       $('.titlea').hide("slide", { 
        direction: "right" 
       }, 200, function() { 
        $('.titleb').hide("slide", { 
         direction: "right" 
        }, 200); 
       }); 
      } 

     }, 
     afterLoad: function(anchorLink, index) { 

      if (index == 1) { 
       $('.titlea').show("slide", { 
        direction: "right" 
       }, 200, function() { 
        $('.titleb').show("slide", { 
         direction: "right" 
        }, 200); 
       }); 
      } 
     } 
    }); 

更具體地講,什麼是多onLeaveafterLoad方法相結合的正確方法?

回答

2

看到,因爲你已經有了,如果在你的事件函數的條款,試試這個

$('#fullpage').fullpage({ 
     onLeave: function(index, nextIndex, direction){     
      if (nextIndex == 3 || nextIndex == 1) { 
       $('.aboutme').hide("slide", { direction: "left" }, 200); 
      } else if (nextIndex == 2) { 
       $('.titlea').hide("slide", { direction: "right" }, 700, function(){$('.titleb').hide("slide", { direction: "right" }, 200);}); 
      } 
     }, 
     afterLoad: function(anchorLink, index){ 
      if (index == 2){ 
       $('.aboutme').show("slide", { direction: "left" }, 200); 
      } else if (index == 1) { 
       $('.titlea').show("slide", { direction: "right" }, 700, function(){$('.titleb').show("slide", { direction: "right" }, 200);}); 
      } 
     } 

    }); 

}); 

或使用開關/箱

$('#fullpage').fullpage({ 
     onLeave: function(index, nextIndex, direction){ 
      switch(nextIndex){ 
       case 3: 
       case 1: 
        $('.aboutme').hide("slide", { direction: "left" }, 200); 
        break; 
       case 2: 
        $('.titlea').hide("slide", { direction: "right" }, 700, function(){$('.titleb').hide("slide", { direction: "right" }, 200);}); 
        break; 
      } 
     }, 
     afterLoad: function(anchorLink, index){ 
      switch(index){ 
       case 2: 
        $('.aboutme').show("slide", { direction: "left" }, 200); 
        break; 
       case 1: 
        $('.titlea').show("slide", { direction: "right" }, 700, function(){$('.titleb').show("slide", { direction: "right" }, 200);}); 
        break; 
      } 
     } 

    }); 

}); 

所以基本上,你有一個事件的回調函數,並根據參數通過後,您就要採取的行動做出決定。

+0

哦,我明白了,謝謝你,這是有效的。將在幾分鐘內接受。 –