【问题标题】:Having iframe load after scrolling down on page在页面上向下滚动后加载 iframe
【发布时间】:2016-02-10 17:59:13
【问题描述】:

我有一个基本的 HTML 页面,其中包含大约 20 多个使用 Adob​​e Edge Animate 制作的 HTML 页面 iframe。每页包含一个持续约 3 秒的动画图像。当我向下滚动页面以查看 iframe 时,如何加载/动画?现在它们都在页面加载时加载,除非您刷新页面,否则您无法看到页面底部的动画。

感谢任何帮助。

编辑:现在它只是表格内的 iframe。没有 javascript 等,因为我不确定用它来实现什么。

<table>
<tr><td colspan="2"><strong>160x600 - English/Spanish</strong></td></tr>
<tr>
<td><iframe width="160" height="600" src="2016/160x600/160x600.html"></iframe></td>
<td><iframe width="160" height="600" src="2016/160x600Spanish/160x600Spanish.html"></iframe></td>
</tr>
</table>

这是由 Edge Animate 制作的 HTML 页面:

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=Edge"/>
    <title>Untitled</title>
<!--Adobe Edge Runtime-->
    <script type="text/javascript" charset="utf-8" src="edge_includes/edge.6.0.0.min.js"></script>
    <style>
        .edgeLoad-EDGE-10230890 { visibility:hidden; }
    </style>
<script>
   AdobeEdge.loadComposition('160X600', 'EDGE-10230890', {
    scaleToFit: "none",
    centerStage: "none",
    minW: "0px",
    maxW: "undefined",
    width: "160px",
    height: "600px"
}, {"dom":{}}, {"dom":{}});
</script>
<!--Adobe Edge Runtime End-->

</head>
<body style="margin:0;padding:0;">
    <div id="Stage" class="EDGE-10230890">
    </div>
</body>

【问题讨论】:

  • 请发布与您的问题相关的 JavaScript/jQuery、CSS 和 HTML。使用以下任何或所有服务创建演示:jsFiddle.netCodePen.ioPlunker.coJS Bin 或 sn-p(位于文本编辑器工具栏或 CTRL+M 上的第 7 个图标)。
  • 更新帖子以包含我拥有的代码

标签: javascript jquery html css iframe


【解决方案1】:

Iframe 会在设置了 src 属性时加载。为了防止它们立即加载,您可以将最终的 src 存储为数据属性,然后在它位于视口中时设置它(我稍后会谈到):

<iframe src="about:blank" data-src="https://your-url-goes-here"></iframe>

当您准备好让 iframe 可见时,请执行以下操作:

var iframe=$('#your-iframe-id');//or class, whatever you are using

if (iframe.data('src')){
    iframe.prop('src', iframe.data('src')).data('src', false);
}

这将使 iframe 加载并使其动画运行(假设动画运行 onload,我很宽泛,因为您没有发布代码)。

为了知道您的 iframe 何时可见,您可以使用像 jQuery-visible 这样的库,它可以让您知道某个元素何时可见。然后你可以在iframe 出现时执行上面的代码:

if ($('#your-iframe-id').visible(true)) {
  // The iframe is visible, run the above code
} else {
  // The iframe is NOT visible yet, do nothing
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多