jquery - 第三方iframe内联样式更改

标签 jquery html css wordpress iframe

我需要更改第三方iframe内联样式。如何做到这一点请告诉我。

第 3 方视频播放器通过 iframe 显示我们的网站。它在正常 View 中工作正常,但响应灵敏,无法正确显示。

<iframe src="" style="width: 100%; height: 100%; position: absolute; left: 0; top: 0;" allowfullscreen="true" allowtransparency="true" id="" name="" frameborder="0"></iframe>

我需要仅响应式更改位置和宽度,如何做到这一点?

最佳答案

你可以通过 jquery 来完成。

请使用 $(window).width() 方法获取设备的宽度,并根据条件在文档准备好后将内联 css 应用到 iframe。 例如-

var width = $(window).width();

if(width >= 1080) {
    $("iframe").css("width: 100%; height: 100%; position: absolute; left: 0; top: 0;");
} 

else if(width >= 800 ) {
    $("iframe").css("width: 100%; height: 100%; position: absolute; left: 0; top: 0;");
} 

else if(width >= 400 ) { // for mobile devices
    $("iframe").css("width: 100%; height: 100%; position: absolute; left: 0; top: 0;");
} 

else if(width >= 300 ) { // for mobile devices
    $("iframe").css("width: 100%; height: 100%; position: absolute; left: 0; top: 0;");
}

关于jquery - 第三方iframe内联样式更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50616903/

相关文章:

html - 如何在流体布局中固定高度?

javascript - 以导航栏下拉列表形式添加 Controller 时出现 Angular 注入(inject)错误

jquery - ul 被重叠的 div 隐藏

Chrome 上的 Javascript <span> 按钮启用/禁用

javascript - 我想在 Angularjs 表中显示此 Json 数据

jquery - 较低的 div 在 CSS 和 jQuery 动画中变形

jquery - 我可以将其转换为仅使用地址链接吗?

jquery - Twitter Bootstrap - 导航栏切换不会在索引以外的页面上打开

javascript - 在 :hover 上加载 gif 占位符

php - 使用 php 倒转每个单词