javascript - 使用 JavaScript 滚动 PDF

标签 javascript jquery pdf iframe

我发现了类似的问题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/

相关文章:

VBA 另存为 PDF,文件名作为单元格值

html - iTextSharp HTML 到 PDF 的转换 - 无法更改字体

javascript - Jquery:如何使用现有的输入文本值而不使用像 "change", "keyup"这样的交互

jquery - 如何删除 jQuery UI 可拖动恢复时的动画?

javascript - 如何删除特定类的前一个li?

javascript - 使用点击功能检查多个div中的数据属性值

pdf - 摆脱 matlab 图的 pdf 输出周围的空白

javascript - 防止默认不起作用

javascript - 根据下拉选择更改图像

javascript - 返回深度嵌套数组中对象索引的函数