2014-04-18 20 views
0

我對jQuery相當新,我試圖讓我的移動菜單(通過菜單按鈕打開)滾動到該部分並關閉一旦鏈接被按下。 我遇到的問題是我的所有鏈接仍然滑動菜單。只有關閉移動導航,如果鏈接有類

我只想要類「menu_links」的鏈接來滑動菜單。

(CSS的顯示部分是確保頁面處於移動模式切換菜單前,我並沒有與它的問題)

請可能有人向我解釋什麼,我做錯了,更好的方式來做到這一點?任何幫助將非常感激!

//Smooth scrolling 
$(document).ready (function() { 
    $('a[href*=#]:not([href=#])').click(function() { 
     if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) { 
     var target = $(this.hash); 
     target = target.length ? target : $('[name=' + this.hash.slice(1) +']'); 
     if (target.length) { 
      $('html,body').animate({ 
      scrollTop: target.offset().top 
      }, 1000); 

      //Issues area 
      if ($("a").hasClass("menu_links")) { 
      if ($(".menuButton").css("display") == "block"){ 
       $(".menu").slideToggle("medium"); 
      } 
      } 
      return false; 
     } 
     } 
    }); 
}); 
+0

解釋哪些行代碼將是錯誤的????我看不到任何錯誤的代碼,但提供小提琴會更好.... –

+0

我剛剛標記了我懷疑是錯誤的行//問題區域 – jb93

回答

0

更改的行:

if ($("a").hasClass("menu_links")) { 

if ($(this).hasClass('menu_links')) {