2015-05-15 29 views
1

只需點擊一個按鈕,我想讓頁面滾動某個格bottom

的第一時間我點擊,頁面將會非常頂部和初始URL http://localhost:8000成爲http://localhost:8000/#/bottom爲什麼它不會去div我提到)。

的第二次我按一下按鈕,則網址 http://localhost:8000/#/bottom#bottom和它去到div bottom這正是我想要)。

我該如何處理?

代碼片段

$location.hash('bottom'); 
$anchorScroll(); 

在此先感謝

做,如果需要尋求更多的解釋。 。 。

+0

也許你使用[ui-router](https://github.com/angular-ui/ui-router)和頁面重新渲染散列變化? –

+0

不,我不使用ui路由器 – dreamer

回答

-3
<a href="#bottom">BOTTOM</a> 
<div style="height:700px"> this is boby </div> 
<a href="https://www.facebook.com/vietlink365" id="bottom">JOIN NOW!</a> 
+1

保持某種解釋atleast – dreamer

0

我不知道,如果你還需要幫助,但你檢查this問題嗎?

反正,我也用一個按鈕做錨滾動:

<button ng-click="app.gotoAnchor('destination')">GO!</button> 
(...) 
<div id="destination" style="height:1px;"></div> 

而我只是用AngularJS文檔examples和我前面提到的SO問題的組合,使這個功能:

function gotoAnchor(anchor){ 
     if ($location.hash() !== newHash) { 
     // set the $location.hash to `newHash` and 
     // $anchorScroll will automatically scroll to it 
     $timeout(function() { 
      $location.hash(anchor); 
     }); 
     } else { 
     // call $anchorScroll() explicitly, 
     // since $location.hash hasn't changed 
     $anchorScroll(); 
     } 
    } 

作爲$timeout打電話讓這個工作更好。

希望這會有所幫助。