解决angular单页面页面底部跳转到新页面滚动条不在顶部的问题

 以上jquery,下面js

this.router.events.subscribe((event) => {
	document.body.scrollTop=0;
});

 

另一种写法

import { Component, ViewEncapsulation, OnInit } from '@angular/core';
import { Router, ActivationEnd, NavigationEnd } from '@angular/router';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.less','../assets/css/style.less'],
  encapsulation: ViewEncapsulation.None //Emulated当前  None全局
})
export class AppComponent {
  title = '数据平台';
  constructor(private  router: Router){
  	
  }
  ngOnInit(){
  	 this.router.events.subscribe((event:NavigationEnd) => {
  		if (event instanceof ActivationEnd){// 当导航成功结束时执行
	    	document.documentElement.scrollTop = 0;
	    	//document.body.scrollTop.scrollTop = 0;
  		}
		});
  }
}

  

  

 

相关文章:

  • 2021-10-20
  • 2022-12-23
  • 2021-09-25
  • 2022-02-27
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-24
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-03-02
  • 2021-07-24
  • 2022-12-23
相关资源
相似解决方案