z-index and iFrames!

2019-01-10 18:47发布

I'm using the FancyBox plugin for some of my site's images. On one of my pages, I also have the embedded iFrame code from YouTube to place a video on the page.

On this same page is a thumbnail that, when clicked, FancyBoxes the image. However, the embedded YouTube video still lays over the FancyBox image. I did a bit of z-index experimenting and still no luck.

Does an iFrame have seniority over all elements in a page even with z-index set, etc.?

6条回答
做个烂人
2楼-- · 2019-01-10 19:21

Is very simple, just add this parameters to your iframe url and thats it:

<iframe title="YouTube video player" width="480" height="390" src="http://www.youtube.com/embed/lzQgAR_J1PI?wmode=transparent" frameborder="0" wmode="Opaque">

Good luck!

查看更多
劳资没心,怎么记你
3楼-- · 2019-01-10 19:24

To get this to work in IE (at least 7 and 8) you must add this:

<param name="wmode" value="transparent" />

I don't believe there is a way to append this to the iframe URL so your content needs to have this, probably between object tags.

查看更多
家丑人穷心不美
4楼-- · 2019-01-10 19:25

If you want the Flash applet to be rendered according to the same z-index rules of any other HTML element, then you need to set the WMODE attribute for the included flash.

See:

  1. http://www.communitymx.com/content/article.cfm?cid=E5141
  2. differences between using wmode="transparent", "opaque", or "window" for an embedded object on a webpage
查看更多
疯言疯语
5楼-- · 2019-01-10 19:27

Hmm, the problem here is that I don't have control over the flash elements. I'm basically just pulling the embedded iFrame HTML from the youtube site which only contains the tags. So I can't set the WMODE attribute.

Late answer but: yes you can. Just tack ?wmode=opaque onto the yt url.

<iframe src="http://www.youtube.com/embed/vRH3Kq5qDw4?wmode=opaque".............
查看更多
小情绪 Triste *
6楼-- · 2019-01-10 19:32

Add wmode=transparent as param.

Html solution

<iframe title="YouTube video player" 
width="480" height="390" 
src="http://www.youtube.com/embed/lzQgAR_J1PI?wmode=transparent" 
frameborder="0"
>

jQuery solution:

$(document).ready(function () {
    $('iframe').each(function(){
        var url = $(this).attr("src");
        $(this).attr("src",url+"?wmode=transparent");
    });
});

Source http://www.scorchsoft.com/news/youtube-z-index-embed-iframe-fix

查看更多
你好瞎i
7楼-- · 2019-01-10 19:34

In a word, yes. However Youtube videos are Flash. Flash also has seniority over the Z-order. It will overlay whether it is in an IFRAME or not.

IFRAME and Flash are "heavyweight" objects. They have their own Window Manager objects (HWND in Windows), so they are either in front of other heavyweight objects or behind them.

div, span, etc are "lightweight". That is they are drawn objects, drawn onto the Body (which is a heavyweight object), and managed by the browser, not the window manager.

As far as the operating system window manager is concerned, they are just pretty pictures drawn by the browser. That's why they cannot overlay "real" objects (or what the window manager thinks of as real).

They have to be lightweight because they would rapidly exhaust the window manager if every DIV and SPAN and A had to reserve OS resources.

查看更多
登录 后发表回答