可见时加载iframe [英] Have iframe load when visible

查看:90
本文介绍了可见时加载iframe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含约100个视频的网页(youtube)加载iframe。他们都在手风琴风格的菜单中,我想知道是否有方法让他们在手风琴开启或页面上可见iframe时加载。现在它占用太多内存并且滞后页面很多。

解决方案

您没有显示任何代码,允许我们在代码中包含此代码。

不要设置视频的src,将其存储在数据中

 < iframe src = about:blankdata-src =http://youtu.be/etc>< / iframe> 

使用手风琴的任何触发器,$(this)就是手风琴项目

  var $ iframe = $(this).find('iframe'); 
if($ iframe.data('src')){//只在iframe中执行一次
$ iframe.prop('src',$ iframe.data('src'))。data ('src',false);
}


I have a page with about 100 videos on them (youtube) loading an iframe. They are all in an accordion style menu, I was wondering if there was a way to have them load when the accordion is open or the iframe is visible on the page. Right now it takes up way too much memory and lags the page a lot.

解决方案

You haven't shown any code that allows us to include this in your code.

Don't set the src of the video, store it in data

<iframe src="about:blank" data-src="http://youtu.be/etc"></iframe>

Using whatever triggers the accordion, $(this) being that accordion item

var $iframe=$(this).find('iframe');
if ($iframe.data('src')){ // only do it once per iframe
    $iframe.prop('src', $iframe.data('src')).data('src', false);
}

这篇关于可见时加载iframe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆