简体   繁体   English

在中收听滚动事件<object>

[英]Listen for a scroll event in <object>

I have a PDF in an HTML object tag like so: 我在HTML对象标签中有一个PDF,如下所示:

<object type="application/pdf" data="https://termsfeed.com/assets/pdf/privacy-policy-template.pdf"></object>

and I would like to run some code when the PDF is scrolled. 当PDF滚动时,我想运行一些代码。 However, attaching a scroll event listener to the object element doesn't work. 但是,将滚动事件侦听器附加到object元素不起作用。 What is the correct way to get this working? 使此工作正常的正确方法是什么?

listen to the scroll event of container html element instead of pdf 监听容器html元素而不是pdf的滚动事件

<div id='pdfContainer'>
   <object type="application/pdf" data="https://termsfeed.com/assets/pdf/privacy-policy-template.pdf"></object>
</div>

$('#pdfContainer').on('scroll', function () {
        alert('scrolling');
    });

 document.getElementById('pdfContainer').addEventListener('scroll', function () { console.log('scrolling'); }); 
 object { height: 1200px; } #pdfContainer { height: 500px; overflow-y: scroll; } 
 <div id='pdfContainer'> <object type="application/pdf" data="https://termsfeed.com/assets/pdf/privacy-policy-template.pdf"></object> </div> 

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

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