简体   繁体   English

如何捕获div元素末尾的滚动条position?

[英]How to capture the scroll position at the end of the div element?

I would like to capture scroll position at the end of the specific div element.我想在特定 div 元素的末尾捕获滚动 position。 But I couldn't fix that.但我无法解决这个问题。 What should I do?我应该怎么办? Could you please help me about this situation?你能帮我解决一下这种情况吗? Here is the following basic application link regarding my issue.以下是关于我的问题的基本应用程序链接。 Thanks for your help and suggestions.感谢您的帮助和建议。

在此处输入图像描述

I think it is better to use Intersection Observer for what you want to do.我认为最好将 Intersection Observer 用于您想要做的事情。 So you could do something like this:所以你可以这样做:

var observer = new IntersectionObserver(function(entries) {
    if(entries[0].isIntersecting === true)
        alert('hello');
}, { threshold: [1] });

observer.observe(document.querySelector(".launch-alert"));

Simply add a div with the class launch-alert at the end or your content and when it will be fully visible your alert will be trigger.只需在末尾或您的内容添加一个带有 class 启动警报的 div,当它完全可见时,您的警报就会被触发。

Hope this helps希望这可以帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM