2015-04-28 98 views
2

我的下拉菜單與bootstraps工作,但只有內部鏈接。我希望它與外部聯繫工作bootstrap下拉菜單外部鏈接

www.speleobox.be/test

這是我的代碼:

<!-- BEGIN NAVIGATION --> 
<ul class="nav navbar-nav"> 
    <li class="dropdown"> 
     <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">Huur uw... <span class="caret"></span></a> 
     <ul class="dropdown-menu" role="menu"> 
      <li><a href="http://www.speleobox.be">Speleobox</a></li> 
      <li><a href="http://www.sumopak.be">Sumopakken</a></li> 
     </ul> 
    </li> 
    <li><a href="#experience">Speleobox</a></li> 
    <li><a href="#pricing-tables">Prijzen</a></li> 
    <li><a href="#contact-us">contact</a></li> 
</ul> 
<!-- END NAVIGATION --> 

回答

0

,我看到你有一個滾動的一些停泊在一個自定義代碼碼。所以這可以防止默認的onclick事件,即使是外部鏈接。

//smooth scroll to href value 
jQuery(".tabs-btn ul li a, .navbar-nav li a, .navbar-brand").click(function(event){ 
    event.preventDefault(); 
    //calculate destination place 
    var dest=0; 
    if($(this.hash).offset().top > $(document).height()-$(window).height()){ 
      dest=$(document).height()-$(window).height(); 
    }else{ 
      dest=$(this.hash).offset().top; 
    } 
    //go to destination 
    jQuery('html,body').animate({scrollTop:dest}, 1000,'swing'); 
}); 

也有是在代碼中的錯誤,你可以在開發者控制檯中看到

Cannot read property 'top' of undefined 

我建議刪除此代碼,並與這一個 https://css-tricks.com/snippets/jquery/smooth-scrolling/

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

此將其交換功能很好,我用了很多次。

+0

非常感謝! –