简体   繁体   English

定位嵌入JavaScript的元素

[英]Positioning an element embedded in a JavaScript

I'm not yet into javascript myself, so I need your help. 我本人还没有学习javascript,因此需要您的帮助。 Situation is that I have a '< script >'-element in an html-document, which embeds a swf-file. 情况是我在html文档中有一个“ <script>”元素,该元素嵌入了swf文件。 Now I want to position said embedded swf. 现在,我要定位所说的嵌入式瑞士法郎。 Here's the code: 这是代码:

<!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>

unfortunately positioning doesn't work that way. 不幸的是,定位不能那样工作。 Thanks to the red border I can see that the "game"-div is exactly where I want it to be. 多亏了红色边框,我可以看到“ game” -div正是我想要的位置。 The embedded swf though is still in the upper left corner and refuses to be moved by the surrounding div and its css-commands. 嵌入的swf仍然位于左上角,并且拒绝被周围的div及其css命令移动。

How can I position the swf? 如何放置瑞士法郎?

The div block #game only holds the Javascript block. div块#game仅保存Javascript块。 SWFObject replaces the content in the div #altContent (named as second parameter in the function embedSWF) with your SWF. SWFObject用您的SWF替换div #altContent (在embedSWF函数中命名为第二个参数)中的内容。 So you should (as you already mentioned yourself in the comments) put the #altContent div in the #game div like: 所以,你应该(因为你已经在评论中提到自己)把#altContent格在#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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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