angularjs专注于移动设备上的元素

时间:2014-07-21 02:13:53

标签: angularjs mobile cross-browser

我正在使用angularjs开发单页面应用程序,并希望它可以在浏览器中运行。但是,当我在我的nexus 5手机上测试它时,当我尝试在放大屏幕上浏览不同的功能时出现问题中心始终位于整个页面的中心有时会让用户觉得它们在空白页面上(因为活动元素位于页面的左上角)是否有一种简单的方法可以在重定向发生时将焦点放在页面的特定元素上?感谢。

1 个答案:

答案 0 :(得分:0)

您可以使用$ route的$ routeChangeSuccess事件,并且您可以使用$ anchorscroll服务。

代码段:

$scope.$on('$routeChangeSuccess', function (scope, next, current) {
    $location.hash('<ur top div id>');
    $anchorScroll();
}

您需要为anchorScroll注入相同的依赖项。

ngRoute Documentation for routeChangeSuccess event