简体   繁体   English

缩放HTML5嵌入的SWF文件以适合div尺寸

[英]Scale HTML5 embed swf to fit in div dimensions

I have the following setup: 我有以下设置:

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

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

I would like the embed swf file to fit in this dimensions but scale does not do what i want. 我希望嵌入的swf文件适合此尺寸,但缩放比例无法满足我的要求。 I also tried width=100% and height=100% but makes the swf file gets all the space and when there are letters coming outside the scene they are visible. 我还尝试了width = 100%和height = 100%,但是使swf文件获得了所有空间,并且当场景外出现字母时它们是可见的。

One idea is to resize it with javascript but do you have any suggestions on any property of the html5 embed to do this automatically? 一种想法是使用javascript调整大小,但是您对html5的任何属性有任何建议以自动执行此操作吗?

Thanks in advance! 提前致谢!

Finally did that with js, i used the following function to calculate the new dimensions based on the container i would like the embed element to be. 最终使用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.

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