[英]Having iframe load after scrolling down on page
我有一个基本的HTML页面,其中包含使用Adobe Edge Animate制作的大约20多个iframe HTML页面。 每页包含一个动画图像,持续约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
存储为数据属性,然后将其设置在视口中(稍后我将介绍):
<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
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.