1

单击按钮时,我希望页面滚动特定的 div bottom

我第一次单击时,页面将转到最顶部,并且初始 url http://localhost:8000变为http://localhost:8000/#/bottom为什么它不转到div我提到的)。

我第二次单击按钮时,url 变为 http://localhost:8000/#/bottom#bottom并转到 div bottom这就是我想要的)。

我该如何处理?

代码片段

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

提前致谢

如果需要,请寻求更多解释。. .

4

2 回答 2

0

我不知道您是否还需要帮助,但是您检查过这个问题吗?

无论如何,我也使用一个按钮来做一个锚滚动:

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

我只是结合了 AngularJS 文档示例和我之前提到的 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使这项工作变得更好的电话。

希望这可以帮助。

于 2015-08-07T15:05:05.817 回答
-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>
于 2015-05-15T08:03:21.013 回答