2014-09-27 131 views
0

我試圖讓我的網站向下滾動,當我點擊一個箭頭。它可以在這裏查看http://www.divisionforty.com/dbarr/jQuery滾動到不工作

但是,由於某種原因,點擊上沒有任何事情發生。它根本不起作用。我在其他div上嘗試過,沒有更好的運氣。

<script> 
    $(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; 
       } 
      } 
     }); 
    }); 
</script> 

希望有人可以提供幫助。

感謝,
丹佛

+0

檢查'target.length',快速測試在控制檯中運行您的代碼的幾個鏈接返回'0'。設置一個斷點並逐步完成代碼 – charlietfl 2014-09-27 15:59:59

回答

1

那是因爲你的#circlediva標籤在視覺上不可見(有寬度和高度等於零)!

你必須做的是與a元素來包裝#circlediv,如下:

<div class="upper">   
    <a href="#article"> 
     <div id="circlediv"> 
     </div> 
    </a> 
</div> 
+0

非常感謝您的幫助! – Denver 2014-09-27 16:17:51

+0

不客氣;) – 2014-09-27 16:19:31

+0

HMM,它還是不想加載 – Denver 2014-09-27 16:20:00

0

我檢查你的DOM元素並沒有如UL或東西。 見這個例子中的DOM元素在這個例子中使用的名稱SmoothPageScroll具有下面的結構,你必須做出這樣的事情在您的網站:

<div id="page-wrap"> 

     <h1 id="top">Smooth Page Scrolling</h1> 
     ... 
     <ul> 
      <li><a href="/examples/SmoothPageScroll/#two">Scroll to Section Two</a></li> 
      <li><a href="#three">Scroll to Section Three</a></li> 
     </ul> 

     <h1 id="one">Section One</h1>  
     ... 
     <h1 id="two">Section Two</h1>   
     ... 
     <p><a href="#top">Top</a></p> 

    </div> 
0

我檢查你的網頁現在發現了這一點:

<a>標籤內circlediv和它的大小是0x0像素,所以你不能點擊它。

試試這個:

<a href="#article"> 
    <div id="circlediv"> 
    </div> 
</a> 

其次,你沒有任何元素與id='article',所以它沒有找到任何元素滾動到。