javascript - 移动网站的滚动助手

标签 javascript angularjs cordova web-applications scroll

我有一个很长的文章页面,我想帮助移动用户滚动。对于移动应用程序中很长的列表,通常有一个字母索引,可以帮助用户跳转到列表中的各个位置。如何为网络应用程序实现类似的功能?

如果它有帮助,我的堆栈是 angularjs/jquery/PhoneGap。

最佳答案

只需使用 Angular 的内置 $anchorScroll 服务即可。

请参阅live example in angular's official docs 。以下是重要的代码片段:

在您的 View 模板中:

<div id="scrollArea" ng-controller="ScrollCtrl">
  <a ng-click="gotoBottom()">Go to bottom</a>
  <a id="bottom"></a> You're at the bottom!
</div>

在你的 Controller 中:

function ScrollCtrl($scope, $location, $anchorScroll) {
  $scope.gotoBottom = function (){
    // set the location.hash to the id of
    // the element you wish to scroll to.
    $location.hash('bottom');

    // call $anchorScroll()
    $anchorScroll();
  };
}

关于javascript - 移动网站的滚动助手,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23657542/

相关文章:

javascript - NodeJS 事件处理机制的用例

javascript - 如何从google maps api获取国家?

javascript - AngularJS 重复但根据条件删除嵌套部分

android - 手机间隙 : Image size and keypad issue

javascript - 在 phonegap 中的 2 个 html 页面之间导航

android - 从远程进程调用 Cordova 回调

javascript - 在同一 aspx 页面上的 commandArgument 中传递选定的下拉文本?

javascript - 带有原型(prototype)的 javascript 中的 for() 上的 "this[key]"

caching - AngularJS 中防止 IE 缓存的更好方法?

javascript - AngularJS中如何将第三方库回调(firebase)的数据传递给View