Angular - 锚点滚动延迟
创始人
2024-10-14 19:01:05
0

在Angular中实现锚点滚动延迟的解决方法是使用ScrollingModuleViewportScroller

首先,确保在app.module.ts中导入ScrollingModule

import { ScrollingModule } from '@angular/cdk/scrolling';

@NgModule({
  imports: [
    // ...
    ScrollingModule
  ],
  // ...
})
export class AppModule { }

然后,在组件中注入ViewportScroller

import { Component, Inject } from '@angular/core';
import { ViewportScroller } from '@angular/common';

@Component({
  // ...
})
export class YourComponent {
  constructor(
    @Inject(ViewportScroller) private viewportScroller: ViewportScroller
  ) { }

  scrollToAnchor(anchor: string): void {
    this.viewportScroller.scrollToAnchor(anchor);
  }
}

最后,在模板中使用锚点并调用scrollToAnchor方法:

Section 1
Section 2

Section 1 Content
Section 2 Content

这样,当用户点击锚点链接时,页面将平滑滚动到对应的锚点位置。

相关内容

热门资讯

发现一款!wpk透视插件,we... 1、发现一款!wpk透视插件,wepoker轻量版透视系统,总结教程(有挂技巧);详细教程。2、we...
安装程序教程!wepoker有... 安装程序教程!wepoker有用吗,wepoker私人局辅助挂,教你教程(有挂方法),支持语音通讯、...
重大通报!wepoker有脚本... 重大通报!wepoker有脚本吗,wepoker私人局透视插件,2025新版(有挂攻略);玩家必备必...
一分钟了解!wepoker透视... 一分钟了解!wepoker透视脚本免费app,we-poker是什么软件,解密教程(有挂辅助)1、点...
关于!we-poker辅助软件... 《关于!we-poker辅助软件教程,智星德州插件,可靠教程(有挂辅助)》 we-poker辅助软件...
专业讨论!hhpoker开挂教... 专业讨论!hhpoker开挂教程,wpk透视插件,教你攻略(有挂透明)科技教程也叫必备教程,这是一款...
玩家必备科技!pokemmo脚... 1、玩家必备科技!pokemmo脚本辅助器下载,aapoker脚本怎么用,攻略方法(有挂攻略);详细...
分享实测!wepoker正确养... 分享实测!wepoker正确养号方法,wepoker有用吗,我来教教你(有挂辅助);1分钟了解详细教...
揭秘攻略!哈糖大菠萝能开挂吗,... 揭秘攻略!哈糖大菠萝能开挂吗,wepoker好友房开挂,透明挂教程(有挂教程);科技安装教程;136...
程序员教你!德州局HHpoke... 程序员教你!德州局HHpoker透视脚本,wepoker透视脚本网页,必备教程(有挂辅助)是一款可以...