解决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;
  		}
		});
  }
}

  

  

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM