我试图在同一页面上做一个简单的滚动到一个锚元素.基本上,该人点击"试一试"按钮,它会滚动到页面下方的区域,其ID为"登录".现在,它正在使用一个基本的id="login",<a href="#login"></a>但它跳到那个部分.理想情况下,我希望它滚动到那里.如果我使用的是Angular4,是否有一些内置方法可以做到这一点或者最简单的方法是什么?谢谢!
整个模板......(组件仍然是空的)
<div id="image-header">
<div id="intro">
<h1 class="text-center">Welcome to ThinkPlan</h1>
<h3 class="text-center">Planning your way</h3>
<a class="btn btn-outline-primary" href="#login" id="view">Try It</a> <!-- Where the user clicks to scroll -->
</div>
</div>
<div class="container" id="info">
<div class="row">
<div class="col-md-12">
<div class="space" id="login"></div> <!-- The place to scroll to -->
<h1 class="text-center">ThinkPlan</h1>
<form class="form-horizontal">
<fieldset>
<legend>Login</legend>
<div class="form-group">
<label for="inputEmail" class="col-lg-2 control-label">Email</label>
<div class="col-lg-10">
<input type="text" class="form-control" id="inputEmail" placeholder="Email">
</div>
</div>
<div class="form-group">
<label for="inputPassword" class="col-lg-2 control-label">Password</label>
<div …Run Code Online (Sandbox Code Playgroud) 我有一个链接,通过单击该链接,我想滚动到页面底部的一个片段。当我点击链接时,片段正在工作,但它没有将它带到页面顶部。
我尝试使用带有 id 的 div 和 section 来创建片段。但是,它不会将 div 或部分带到页面顶部。
我的应用程序路由模块中的代码是:
imports: [
RouterModule.forRoot(routes, {
//useHash: true,
scrollPositionRestoration: 'enabled',
onSameUrlNavigation: 'reload',
anchorScrolling: 'enabled'
})]
Run Code Online (Sandbox Code Playgroud)
我的链接和片段组件代码:
<a [routerLink]="['/proposal']" fragment="dcn">{{ dcn }}</a>
<section id="dcn">
Some other html here
</section>
Run Code Online (Sandbox Code Playgroud)
请注意,我曾尝试使用useHash:true,但似乎不起作用。我更喜欢一个useHash不真实的解决方案。