【问题标题】:Scale HTML5 embed swf to fit in div dimensions缩放 HTML5 嵌入 swf 以适应 div 尺寸
【发布时间】:2015-03-03 08:45:48
【问题描述】:

我有以下设置:

<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 嵌入的任何属性有什么建议可以自动执行此操作吗?

提前致谢!

【问题讨论】:

    标签: javascript html embed flash


    【解决方案1】:

    最后用 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) };
    };
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-24
      • 1970-01-01
      • 1970-01-01
      • 2011-05-08
      • 2012-04-09
      • 1970-01-01
      • 2017-05-29
      • 1970-01-01
      相关资源
      最近更新 更多