2016-08-03 85 views
0

我有this website,並且Smoothscroll javascript和lightbox之間存在衝突。SmoothScoll和燈箱衝突

下面是滾動

$(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); 
      return false; 
     } 
     } 
    }); 
    }); 

我怎樣才能解決這個問題的腳本?我怎樣才能使燈箱和平滑的滾動工作同時進行?

+0

頁面上的lightbox觸發器在哪裏?你在哪一點得到這個衝突? –

+0

每當我點擊「Characters」部分中的四個圖像時,一旦我添加了Smoothscroll的代碼,燈箱就不再工作了。 –

回答

0

我不是一個jQuery的專家,不知道該如何選擇靈活的,但這裏有一些建議:

建議1:

我不認爲這個選擇:

a[href*="#"]:not([href="#"]) 

將正常工作。如果他們沒有屬性值「#」,則選擇所有的href元素。我認爲這個案例並沒有涵蓋像你擁有不同價值的鏈接:「#皇后蜂」。我認爲你使用不同的選擇器。

建議2:

if (target.length) { 
    $('html, body').animate({ 
     scrollTop: target.offset().top 
    }, 1000); 

    return false; // Try removing the return 
} 

return語句可以防止起泡的情況下,這樣的收藏夾將不會收到它。嘗試刪除它。

+0

非常感謝!第二種解決方案效果很好 –

+0

它實際上顯示了一個問題,這裏的鏈接:http://niclamarino.altervista.org/Layouts/Beeline/5.html#about 每當你點擊菜單鏈接,你就有一個0.5秒的截屏。 發生這種情況除去「返回錯誤」,你有什麼想法我該如何解決這個問題? –

+0

這是因爲沒有return語句,你會回退到href的本地行爲。這將使用錨點跳轉到href中定義的id部分。因此,您可以更改該部分的ID,以便它不會找到任何要跳轉到的內容,或者收回返回語句併爲菜單按鈕使用不同的標記和選擇器。 –