我发现了类似的问题Scroll PDF embedded in HTML但没有看到答案。有人对如何操作 iframe 中显示的 PDF 有任何建议吗?与上一篇文章链接类似,我尝试在 iframe 没有焦点(主页有焦点)时滚动 PDF。
谢谢!
最佳答案
实际上您提供的链接中有答案:
Hardly.
What you might be able to do is to put the iframe into a div with overflow: auto, and give the iframe a very large height value so the containing PDF is at full size. Make the surrounding div less tall than the iframe. When your buttons get clicked, scroll the surrounding div.
I haven't tested it so there may be some snag on the way, but this could work - and is probably the best you can do.
~Pekka 웃
这很容易。这就是你要做的:
这取决于 iframe 是否是“外部”的,而不是来自您的服务器。 就说它是外包的
代码
<div id="iframeContainer" style="width: 800px; height: 600px; overflow: auto;">
<iframe width="1800" height="6000" src="yourPDFfileSRC" scrolling="no">
</iframe>
//You have to know exact width and height of PDF file
</div>
<script type="text/javascript">
$("document").ready(function()
{
$("#iframeContainer").scrollTop(1400);
});
</script>
奖金
你可以像这样设置动画:
<script type="text/javascript">
$("document").ready(function()
{
$("#iframeContainer").animate({scrollTop: 1400}, 500); //500 - time of animation
});
</script>
关于javascript - 使用 JavaScript 滚动 PDF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33154598/