flash wmode引數詳解

Web開發者發表於2012-07-18

  在做web開發中可能會遇到flash遮擋頁面中元素的情況,例如flash遮擋住了下拉選單。無論怎麼設定flash容器和層的深度(z-index)也無濟於事,現有的解決方案是在插入flash的embed或object標籤中加入”wmode”屬性並設定為wmode=“transparent”或”opaque”,但wmode屬性到底是什麼意義,為什麼可以解決這個問題呢?

window mode(wmode)

  wmode即視窗模式總共有三種,看看當年Macromedia官方的說法:

  • Window: Use the Window value to play a Flash Player movie in its own rectangular window on a web page. This is the default value for wmode and it works the way the classic Flash Player works. This normally provides the fastest animation performance.
  • Opaque: By using the Opaque value you can use JavaScript to move or resize movies that don’t need a transparent background. Opaque mode makes the movie hide everything behind it on the page. Additionally, opaque mode moves elements behind Flash movies (for example, with dynamic HTML) to prevent them from showing through.
  • Transparent: Transparent mode allows the background of the HTML page, or the DHTML layer underneath the Flash movie or layer, to show through all the transparent portions of the movie. This allows you to overlap the movie with other elements of the HTML page. Animation performance might be slower when you use this value.


window 模式

  預設情況下的顯示模式,在這種模式下flash player有自己的視窗控制程式碼,這就意味著flash影片是存在於Windows中的一個顯示例項,並且是在瀏覽器核心顯示視窗之上的,所以flash只是貌似顯示在瀏覽器中,但這也是flash最快最有效率的渲染模式。由於他是獨立於瀏覽器的HTML渲染表面,這就導致預設顯示方式下flash總是會遮住位置與他重合的所有DHTML層。

  但是大多數蘋果電腦瀏覽器會允許DHTML層顯示在flash之上,但當flash影片播放時會出現比較詭異的現象,比如DHTML層像被flash刮掉一塊一樣顯示異常。

Opaque 模式

  這是一種無視窗模式,在這種情況下flash player沒有自己的視窗控制程式碼,這就需要瀏覽器需要告訴flash player在瀏覽器的渲染表面繪製的時間和位置。這時flash影片就不會在高於瀏覽器HTML渲染表面而是與其他元素一樣在同一個頁面上,因此你就可以使用z-index值來控制DHTML元素是遮蓋flash或者被遮蓋。

Transparent 模式

  透明模式,在這種模式下flash player會將stage的背景色alpha值將為0並且只會繪製stage上真實可見的物件,同樣你也可以使用z-index來控制flash影片的深度值,但是與Opaque模式不同的是這樣做會降低flash影片的回放效果,而且在9.0.115之前的flash player版本設定wmode=”opaque”或”transparent”會導致全屏模式失效。

  瞭解了各種模式的實現方式和意義在以後的開發中就可以按照具體情況選擇設定wmode屬性的值了。