2015-02-23 98 views
0

我正在使用兩個jQuery插件fullpage和ferromenu。初始化/未初始化一個jQuery插件頁更改

fullpage使窗口滾動整個頁面,ferromenu是一個整齊的圓形菜單,可以擴展和摺疊。

的問題是,由於全頁讓我的整個網站的一個頁面,ferromenu每一個頁面上顯示,所以我不希望只是用$(文件)進行初始化。就緒

這是我試過,但我現在的問題是,當頁面改變從網址遠

$(window).on('hashchange', function(e){ 

var pageURL = $(location).attr("href"); 

if (pageURL === "https://www.example.com/index.php#thirdPage") { 
    $("#custom-nav").ferroMenu({ 
      position : "center-center" 
    }); 
}; 

}); 

回答

1

你應該使用fullPage.js如onLeaveafterLoad提供的回調:

$(document).ready(function() { 
    $("#custom-nav").ferroMenu({ 
     position: "center-center" 
    }); 

    $('#fullpage').fullpage({ 
     anchors: ['firstPage', 'secondPage', 'thirdPage', 'fourthPage', 'lastPage'], 

     onLeave: function (index, nextIndex, direction) { 
      //going to section 3 ? 
      if (nextIndex == 3) { 
       $('.ferromenu-controller').show(); 
      } else { 
       $('.ferromenu-controller').hide(); 
      } 

     } 
    }); 
}); 

甚至通過使用fullpage.js加入到體內的CSS3類,如this tutorial詳細。

0

我不知道這是否是做的最好的方式,但我發現類爲它不會消失它創建的html對象,只是改變了我的if語句的else部分中的顯示屬性。

$(window).on('hashchange', function(e){ 

var pageURL = $(location).attr("href"); 

if (pageURL === "https://www.example.com/index.php#thirdPage") { 
    $("#custom-nav").ferroMenu({ 
      position : "center-center" 
    }); 
} else { 
    $('.ferromenu-controller').css('display', 'none'); 
}; 

});