[英]How can i access window object in the angular5 in the way we do this “ @ViewChild('fileInput') inputEl: ElementRef” for DOM elements?
我試圖搜索與我的問題有關的已問問題,但解決方案無濟於事。
我想在打字稿中做滾動效果,類似於使用Jquery代碼而不是使用“ jquery
”模塊的代碼片段。 我關心的是按照angular5
准則執行此angular5
,同時要記住服務器端渲染(角度通用)。
onWindowScroll(event){
if(window.scrollY >=350){
console.log("some_value"+window.scrollY);
$('.evaluate-h1').addClass('animated fadeInUp')
}
}
npm install smoothscroll-polyfill --save
然后將其添加到您的polyfill.ts
文件中:
/**
* Polyfill for smooth scrollIntoView()
*/
require('smoothscroll-polyfill').polyfill();
之后,您可以使用普通javascript .scrollIntoView()
滾動到ElementRef:
const element:HTMLElement = this.document.getElementById(this.slug);
if(element) element.scrollIntoView({
behavior: 'smooth',
block: 'start'
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.