简体   繁体   English

Facebook 页面插件 - 响应式

[英]Facebook Page Plugin - Responsive

I need to embed a Facebook Page Plugin on a website.我需要在网站上嵌入 Facebook 页面插件。 According to the info on根据有关资料

https://developers.facebook.com/docs/plugins/page-plugin https://developers.facebook.com/docs/plugins/page-plugin

it can be any width between 180px and 500px它可以是 180px 和 500px 之间的任何宽度

On large screen I want 500px width, but on smaller it would need to something around 300px.在大屏幕上我想要 500 像素的宽度,但在较小的屏幕上它需要大约 300 像素。

Now, there is an option which makes the iframe adjust to the width of the container, but that part of it doesn't work for me at all.现在,有一个选项可以让iframe调整到容器的宽度,但它的那部分对我来说根本不起作用。

So, what I have is two iframes (one for 500px width, one for 300px), and using @media queries, I hide/show the correct one.所以,我有两个 iframe(一个用于 500px 宽度,一个用于 300px),并且使用@media查询,我隐藏/显示正确的一个。

However, it still loads two iframes.但是,它仍然加载两个 iframe。

Is there an equivalent <picture> / <video> tag I could use, which would load only one, depending on screen-width?是否有我可以使用的等效<picture> / <video>标签,它只会加载一个,具体取决于屏幕宽度?

Alternatively, what I am doing wrong with the iframe ?或者,我对iframe做错了什么?

Below is the code replicated in jsfiddle:下面是在 jsfiddle 中复制的代码:

https://jsfiddle.net/nuy4r1gk/2/ <-- 2 iframes https://jsfiddle.net/nuy4r1gk/2/ <-- 2 个 iframe

As you can see, it works, but it's loading two iframes, which is far from good.正如您所看到的,它可以工作,但它正在加载两个 iframe,这远远不够好。 If I use css styling ( @media ) on the iframe, it just cuts it off, rather that loading narrower.如果我在 iframe 上使用 css 样式( @media ),它只会将其切断,而不是加载更窄。

https://jsfiddle.net/nuy4r1gk/4/ <-- 1 iframe with css https://jsfiddle.net/nuy4r1gk/4/ <-- 1 个带有 css 的 iframe

I found a working solution when using the iFrame embed method.我在使用 iFrame 嵌入方法时找到了一个有效的解决方案。 It works with any container width between the supported 180-500px它适用于受支持的 180-500 像素之间的任何容器宽度

https://stackoverflow.com/a/52459262/10401291 https://stackoverflow.com/a/52459262/10401291

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM