gpt4 book ai didi

javascript - 带有长内容的 Angular 注入(inject)页面会使整个页面加载到页面顶部以下,从而切断页面标题

转载 作者:太空狗 更新时间:2023-10-29 14:15:52 26 4
gpt4 key购买 nike

请看下面的 plunker,当您点击 link onelink three 时,页面不会加载到页面顶部,因此您看不到页面标题,您实际上必须向上滚动才能看到页面标题。为什么是这样?我怎样才能让它在顶部加载页面,就像普通网页一样?

Here's the plunker .

这是我的js:

var routerApp = angular.module('routerApp', ['ui.router','ui.bootstrap']);

routerApp.config(function($stateProvider, $urlRouterProvider, $locationProvider) {

$urlRouterProvider.otherwise('/home');
$locationProvider.html5Mode(false).hashPrefix("");
$stateProvider


// HOME VIEW ========================================
.state('home', {
url: '/home',
templateUrl: 'partial-home.html'
// onEnter: scrollContent
})

// ONE VIEW ========================================
.state('one', {
url: '/one',
templateUrl: 'partial-one.html'
})

// TWO VIEW ========================================
.state('two', {
url: '/two',
templateUrl: 'partial-two.html'
})

// THREE VIEW ========================================
.state('three', {
url: '/three',
templateUrl: 'partial-three.html'
})
});

这是我的 html(有关注入(inject)的页面,请参见上面的 plunker 链接)。

<!DOCTYPE html>
<html>
<head>
<!-- CSS -->
<script data-require="jquery@*" data-semver="2.1.4" src="http://code.jquery.com/jquery-2.1.4.min.js"></script>
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" />
<link rel="stylesheet" href="style.css" />
<!-- JS -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.4/js/bootstrap.min.js"></script>
<script src="http://code.angularjs.org/1.2.13/angular.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.2.8/angular-ui-router.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/0.13.0/ui-bootstrap-tpls.js"></script>
<script src="script.js"></script>
<!-- // base path for angular routing -->
<!--<base href="/" />-->
</head>


<body ng-app="routerApp">


<!-- NAVIGATION -->

<!-- Fixed navbar -->
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" ui-sref="home">Some web page somewhere</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li><a ui-sref="one">Link One</a></li>
<li><a ui-sref="two">Link Two</a></li>
<li><a ui-sref="three">Link Three</a></li>
</ul>

</div><!--/.nav-collapse -->
</div>
</nav>
<!-- End Fixed navbar -->




<!-- MAIN CONTENT -->
<!-- Inject Content Here -->
<div class="container" style="padding-top:68px;">
<div ui-view></div>
</div>





</body>
</html>

最佳答案

autoscroll="false" 添加到您的 ui-view 以防止此行为。

<div class="container" style="padding-top:68px;">
<div ui-view autoscroll="false"></div>
</div>

Plunker demo

参见 the documentation about ui-view and autoscroll directives :

autoscroll (optional)

string

It allows you to set the scroll behavior of the browser window when a view is populated. By default, $anchorScroll is overridden by ui-router's custom scroll service, ui.router.state.$uiViewScroll. This custom service let's you scroll ui-view elements into view when they are populated during a state activation.

关于javascript - 带有长内容的 Angular 注入(inject)页面会使整个页面加载到页面顶部以下,从而切断页面标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31436689/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com