定位嵌入在JavaScript中的元素

时间:2013-07-04 09:17:08

标签: javascript css html flash

我自己还没有使用javascript,所以我需要你的帮助。情况是我有'< script>' - html文档中的元素,它嵌入了一个swf文件。现在我想定位所说的嵌入式swf。这是代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8"/>
    <title>Game</title>
    <meta name="description" content="" />
    <script src="js/swfobject.js"></script>
    <style>
        html, body { height:100%; overflow:hidden; }
        body { margin:0; }
        #game {
            width: 1024px;
            height: 768px;
            position: absolute;
            left: 50%;
            top: 5%;
            margin-left: -512px;
            border: 1px solid red;
       }
    </style>
</head>
<body>
<div id="game">
    <script>
        var flashvars = {
        };
        var params = {
            menu: "false",
            scale: "noScale",
            allowFullscreen: "true",
            allowScriptAccess: "always",
            bgcolor: "",
            wmode: "direct" // can cause issues with FP settings & webcam
        };
        var attributes = {
            id:"projectweb2"
        };
        swfobject.embedSWF(
            "projectweb2.swf", 
            "altContent", 1024, 768, "10.0.0", 
            "expressInstall.swf", 
            flashvars, params, attributes);
    </script>
</div>
<div id="altContent">
    <h1>project_web2</h1>
    <p><a href="http://www.adobe.com/go/getflashplayer">Get Adobe Flash player</a></p>
</div>
</body>
</html>
不幸的是,定位不起作用。由于红色边框,我可以看到“游戏”-div正是我想要的地方。嵌入式swf仍然在左上角,并且拒绝被周围的div及其css命令移动。

如何定位swf?

1 个答案:

答案 0 :(得分:1)

div块#game仅包含Javascript块。 SWFObject用您的SWF替换div #altContent中的内容(在函数embedSWF中命名为第二个参数)。所以你应该(正如你在评论中已经提到的那样)将#altContent div放在#game div中,如:

<div id="game">
    <script>
        var flashvars = {
        };
        var params = {
            menu: "false",
            scale: "noScale",
            allowFullscreen: "true",
            allowScriptAccess: "always",
            bgcolor: "",
            wmode: "direct" // can cause issues with FP settings & webcam
        };
        var attributes = {
            id:"projectweb2"
        };
        swfobject.embedSWF(
           "projectweb2.swf", 
            "altContent", 1024, 768, "10.0.0", 
            "expressInstall.swf", 
            flashvars, params, attributes);
    </script>

    <div id="altContent">
        <h1>project_web2</h1>
        <p><a href="http://www.adobe.com/go/getflashplayer">Get Adobe Flash player</a></p>
    </div>
</div>