簡體   English   中英

我如何通過對DOM元素執行“ @ViewChild('fileInput')inputEl:ElementRef”的方式訪問angular5中的窗口對象?

[英]How can i access window object in the angular5 in the way we do this “ @ViewChild('fileInput') inputEl: ElementRef” for DOM elements?

我試圖搜索與我的問題有關的已問問題,但解決方案無濟於事。

Angular_5 =>前端(帶有角度通用)

Node.js =>后端

我想在打字稿中滾動效果,類似於使用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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM