2015-03-03 47 views
0

我有以下設置:規模HTML5中嵌入的SWF以適應DIV尺寸

<div class="creative"> 
    <embed src="..." type="application/x-shockwave-flash" scale="showall" wmode="opaque" allowScriptAccess="always" flashvars="..."/>'; 
</div> 

//==== CSS ==== 
.creative { 
width = 325px; 
height= 350px } 

我想嵌入的SWF文件,以適應這一尺寸,但規模不會做我想要什麼。我也試過width = 100%和height = 100%,但是讓swf文件獲得所有的空間,當有字母出現在場景之外時,它們是可見的。

一個想法是調整它與JavaScript的大小,但你有任何建議的HTML5的任何屬性嵌入自動做到這一點?

在此先感謝!

回答

0

最後這樣做與js,我使用下面的函數來計算基於容器的新維度,我想要嵌入元素。

/* Calculates the new scaled dimensions 
* srcWidth: Swf real width 
* srcHeight: Swf real height 
* maxWidth: Container's width 
* maxHeight: Container's height 
*/ 
function calculateAspectRatioFit (srcWidth, srcHeight, maxWidth, maxHeight) { 
    var ratio = Math.min(maxWidth/srcWidth, maxHeight/srcHeight); 
    return { width: Math.round(srcWidth*ratio), height: Math.round(srcHeight*ratio) }; 
};