[英]Scale HTML5 embed swf to fit in div dimensions
我有以下設置:
<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的任何屬性有任何建議以自動執行此操作嗎?
提前致謝!
最終使用js做到了這一點,我使用以下函數根據我希望embed元素為容器的容器來計算新尺寸。
/* 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) };
};
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.