使用按钮如何以角度6滚动到选定的div

问题描述 投票:0回答:1

嗨,我在这使用Angular6如果我点击按钮它应滚动到选定的div。为此,我使用了npm install ng2-scroll-to --save插件但按钮选择器不起作用请帮我这样做。如果有任何替代解决方案也告诉我。

<a scrollTo href="#main-section">Scroll to main section</a>
        <button scrollTo scrollTargetSelector="#test-section">Scroll to test section</button >
        <button scrollTo scrollableElementSelector="#container" scrollYTarget="0">Go top</button >
        <!-- Further content here -->
        <div id="container">
            <section id="main-section">Bla bla bla</section>
            <section id="test-section">Bla bla bla</section>
        <div>
angular5 angular6 angular2-forms
1个回答
0
投票

您必须将ScroolModule导入到app模块

// app.module.ts
import {ScrollToModule} from 'ng2-scroll-to';

@NgModule({
    imports: [
         ....,
        ScrollToModule.forRoot(),
        ]
})

之后应该没问题。

© www.soinside.com 2019 - 2024. All rights reserved.