Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
313 views
in Technique[技术] by (71.8m points)

html - Angular 7,onWindowScroll事件永远不会触底(Angular 7, Event onWindowScroll never gets bottom)

I'm looking for Scroll event on Angular 7, I need to get to the bottom of the page for call a function to get more information, I found a simple solution here:

(我正在寻找Angular 7上的Scroll事件,我需要到达页面底部以调用函数以获取更多信息,我在这里找到了一个简单的解决方案:)

On the HTML:

(在HTML上:)

<div (scroll)="onWindowScroll($event)"></div>

On the .ts file

(在.ts文件上)

@HostListener("window:scroll", ["$event"])
onWindowScroll() {
let percent = Number(((window.innerHeight + window.scrollY) / 
document.body.offsetHeight)*100).toFixed(3);
   if (Number(percent)==100) {
       this.callContent();
   }
}

But this on some monitor never gets to 100%, I'll show you the result on the console.log.

(但这在某些监视器上永远不会达到100%,我将在console.log上向您显示结果。)

Never gets at 100%

(永远不会达到100%)

The result only gets:

(结果仅得到:)

percent => 99.959 position => 1476.400 bottom => 1477.000

(百分比=> 99.959位置=> 1476.400底部=> 1477.000)

So it never gets to the 100% of the bottom on the page.

(因此,它永远不会到达页面底部的100%。)

But that is the result from monitor 1. Now on monitor 2 I have this:

(但这是监视器1的结果。现在在监视器2上,我得到了:)

100% percent gets

(100%获得)

percent => 100.000 position => 1429.000 bottom => 1429.000

(百分比=> 100.000位置=> 1429.000底部=> 1429.000)

So, when I'm working on the monitor 2, everything goes well, but when I'm working on monitor 1 nothing calls, because never gets to 100% of the bottom page.

(因此,当我在显示器2上工作时,一切正常,但是当我在显示器1上工作时,没有任何响应,因为永远不会到达底部页面的100%。)

Did anyone have this same problem?

(有人遇到过同样的问题吗?)

How can I solve it please, I've been looking many hours for any solution.

(请问如何解决,我一直在寻找任何解决方案的时间。)

Regards and Thanks

(问候和感谢)

  ask by user3123766 translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...