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

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

相关内容

热门资讯

6分钟辅助!约局吧德州有挂吗,... 6分钟辅助!约局吧德州有挂吗,epoker有透视吗,项目教程(真是有挂)1、首先打开约局吧德州有挂吗...
7分钟辅助!pokemmo手机... 7分钟辅助!pokemmo手机版脚本免费,wepoker数据分析工具,手册教程(有挂透视)暗藏猫腻,...
6分钟辅助!aapoker能控... 6分钟辅助!aapoker能控制牌吗,pokemmo脚本最新版,教程书教程(有挂辅助)1、aapok...
第3分钟辅助!werplan脚... 第3分钟辅助!werplan脚本,德普之星透视辅助插件,技法教程(有挂方法)1、德普之星透视辅助插件...
四分钟辅助!wpk是真的还是假... 四分钟辅助!wpk是真的还是假的,we poker辅助器下载,练习教程(有挂解密)1、下载好wpk是...
第2分钟辅助!哈糖大菠萝有挂吗... 第2分钟辅助!哈糖大菠萝有挂吗,hh poker辅助有用吗,指南教程(详细教程)哈糖大菠萝有挂吗脚本...
六分钟辅助!wepoker作弊... 六分钟辅助!wepoker作弊辅助,德州之星扫描器,诀窍教程(有挂秘籍)1、每一步都需要思考,不同水...
第七分钟辅助!wepoker透... 第七分钟辅助!wepoker透视脚本下载,德普之星私人局辅助免费,模块教程(有挂实锤)1、让任何用户...
第6分钟辅助!德州hhpoke... 第6分钟辅助!德州hhpoker脚本,pokemmo手机版脚本免费,妙招教程(有挂神器);1、完成p...
第6分钟辅助!uupoker透... 第6分钟辅助!uupoker透视,wepoker有辅助吗,攻略教程(有挂工具)1、起透看视 wepo...