我正试图用AngularJS创建一个应用程序。目前,我的应用程序中只有一个视图。我的应用程序将有多个视图。此时,我的index.html文件如下所示:
index.html .
Choose:
<a href="/view-1">View 1</a> |
<a href="/view-2">View 2</a>
<div class="view-animate-container">
<div id="driver" ng-view class="view-animate" style="margin: 0; padding: 0; height: 100%;"></div>
</div>
<hr />
</div>
</body>view1.html
<div>
<div style="position:fixed;">
<h1>View 3</h1>
<div>
<a href="#sectionA">Section A</a> | <a href="#sectionB">Section B</a> | <a href="#sectionC">Section C</a>
</div>
</div><br /><br /><br /><br />
<div style="overflow-y:scroll">
<h2 id="sectionA">Section A</h2>
<div style="background-color:navy; color:white;">
Some text content goes here.
<br /><br /><br /><br /><br />
<br /><br /><br /><br /><br />
Yup.
</div>
<h2 id="sectionB">Section B</h2>
<div style="background-color:red; color:white;">
Some text content goes here.
<br /><br /><br /><br /><br />
<br /><br /><br /><br /><br />
Yup.
</div>
<h2 id="sectionC">Section C</h2>
<div style="background-color:peachpuff; color:black;">
Some text content goes here.
<br /><br /><br /><br /><br />
<br /><br /><br /><br /><br />
Yup.
</div>
</div>
</div>main.js
angular.module('myApp', ['ngRoute', 'ngAnimate'])
.config(function ($routeProvider, $locationProvider) {
$routeProvider.when('/view-1', {
templateUrl: '/views/view1.html',
controller: View1Ctrl
});
$routeProvider.when('/view-2', {
templateUrl: '/views/view2.html',
controller: View2Ctrl
});
// configure html5 to get links working on jsfiddle
$locationProvider.html5Mode(true);
})
;
function View1Ctrl($scope, $routeParams) {
this.name = "View1Cntl";
this.params = $routeParams;
}
function View2Ctrl($scope, $routeParams) {
this.name = "View2Cntl";
this.params = $routeParams;
}我试图让我的书签(锚标签)在view1中工作。每当我单击‘A节’、‘B节’或‘C节’时,路线就会被更新。然后视图将重新动画到屏幕上。最后,视图定位到相应的部分。所以问题是视图是重新加载的。实际上,当有人点击书签时,我只想跳到书签上。我如何在AngularJS中做到这一点?
谢谢!
发布于 2014-07-08 20:02:33
我能够使用scrollTo函数完成类似的行为,并将href替换为调用它的ng-click标记。
main.js
$scope.scrollTo = function(selector) {
window.scrollTo(0, $(selector)[0].offsetTop - 100);
}view1.html
<div>
<a ng-click="scrollTo('#sectionA')">Section A</a> |
<a ng-click="scrollTo('#sectionB')">Section B</a> |
<a ng-click="scrollTo('#sectionC')">Section C</a>
</div>
<h2 id="sectionA">Section A</h2>
<div style="background-color:navy; color:white;">
Some text content goes here.
</div>
<h2 id="sectionB">Section B</h2>
<div style="background-color:navy; color:white;">
Some text content goes here.
</div>
<h2 id="sectionC">Section C</h2>
<div style="background-color:navy; color:white;">
Some text content goes here.
</div>发布于 2015-11-30 07:01:31
我得到了最简单的解决方案如下:
将href="#bottom"链接替换/更改为/#/dashboard#bottom
/#/dashboard是我(目前的)/want要滚动的页面,#bottom是锚链接。
我有标签被翻转和使用上述方法,我不能完全解决问题的方式,我想。在上帝的恩典下,我找到了一个小小的讨厌的解决方案:)
https://stackoverflow.com/questions/20840986
复制相似问题