我有一个基本的 HTML 页面,其中包含大约 20 多个使用 Adobe 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>
最佳答案
Iframe 在 src
时加载它们的属性已设置。为了防止它们立即加载,您可以存储最终的 src
作为数据属性,然后在它位于视口(viewport)中时设置它(我稍后会讲到):
<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
时执行上面的代码在 View 中:
if ($('#your-iframe-id').visible(true)) {
// The iframe is visible, run the above code
} else {
// The iframe is NOT visible yet, do nothing
}
关于javascript - 在页面向下滚动后加载 iframe,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35322592/