jquery - 删除 iframe 后将对象置于屏幕中心

标签 jquery html css

我有一个居中的 p我用它来保存我的嵌入式实时流对象和一个用于聊天的 iframe

Unhidden chat

现在,我有一个 JQuery隐藏聊天的电话, <a id="hidechat" onClick="$('#chat_embed').hide();" href="#">[Hide Chat]</a>

但这最终会导致流盒被拉到左边 Hidden chat

我希望聊天在屏幕中央重新对齐,而不是右边那个丑陋的方框。我试过设置 float:left;但它下面的文字环绕并通常会破坏整个布局。

我当前的布局是否可行?

CSS:

    p
    {
        margin-left:auto;
        margin-right:auto;
        margin-bottom:1%;
        background-color:#121212;
        max-width:53%;
        max-height:75%;
        padding-top:25px;
        padding-left:25px;
        padding-right:25px;
        padding-bottom:25px;
    }
    p.streamblock
    {
        padding-top:25px;
        padding-left:25px;
        padding-right:25px;
        padding-bottom:25px;
        max-width:1000px;
    }

嵌入代码:

<object type="application/x-shockwave-flash" height="378" width="620" id="live_embed_player_flash" data="http://www.twitch.tv/widgets/live_embed_player.swf?channel=mychannel" bgcolor="#000000">
    <param name="movie" value="http://www.twitch.tv/widgets/live_embed_player.swf" />
    <param name="flashvars" value="hostname=www.twitch.tv&channel=mychannel&auto_play=true&start_volume=25" />
</object>
<iframe frameborder="0" scrolling="no" id="chat_embed" src="http://twitch.tv/chat/embed?channel=tronasaurusx&amp;popout_chat=true" height="378" width="350"></iframe>

最佳答案

新的 HTML 标记 ->

<div class="streamblock">
  <!-- Twitch.tv embed code -->
<a href="#" onclick="$('#chat_embed').show();$('#showchat').hide();$('#hidechat').show();" id="showchat" style="display: inline;">[Show Chat]</a>
    <a href="#" onclick="$('#chat_embed').hide();$('#hidechat').hide();$('#showchat').show();" id="hidechat" style="display: none;">[Hide Chat]</a><br>
    <p class="objContainer">
  <object width="620" height="378" style="margin: 0px auto;" type="application/x-shockwave-flash" id="live_embed_player_flash" data="http://www.twitch.tv/widgets/live_embed_player.swf?channel=tronasaurusx" bgcolor="#000000">
    <param name="allowFullScreen" value="true">
    <param name="allowScriptAccess" value="always">
    <param name="allowNetworking" value="all">
    <param name="movie" value="http://www.twitch.tv/widgets/live_embed_player.swf">
        <param name="flashvars" value="hostname=www.twitch.tv&amp;channel=tronasaurusx&amp;auto_play=true&amp;start_volume=25">
      </object>
     <!-- End Twitch.tv embed code -->
 <!-- Twitch.tv chat code -->
 <iframe width="350" scrolling="no" height="378" frameborder="0" style="display: none;" id="chat_embed" src="http://twitch.tv/chat/embed?channel=tronasaurusx&amp;popout_chat=true"></iframe>
 <br>
 <!-- End Twitch.tv chat code -->
  </p>
</div>

新的 CSS 标记 ->

div.streamblock{
  margin: 0px auto; 
  text-align: center; 
  max-width:1100px;
}
p{
  background-color: #121212;
  color: #FFFFFF;
  font-family: "Palatino Linotype",Tahoma,Serif;
  margin-bottom: 1%;
  margin-left: auto;
  margin-right: auto;
  max-height: 75%;
  padding: 25px;
  text-indent: 10px;
}

我使用控制台编辑您的 HTML 并即时进行这些更改。以上(当完全按照我给出的方式使用时)将产生所需的结果。

关于jquery - 删除 iframe 后将对象置于屏幕中心,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11497740/

相关文章:

javascript - 运行禁用复选框的 onclick 函数

html - Chrome 和 Internet Explorer 中的 DIV 元素

javascript - 是否可以使用页面滚动条滚动内部 div?

css - 相对于中心定位页面元素

css - 某个类中的每个其他列表项

javascript - jQuery 请求和 d3.js 之间的范围问题

jquery - 在 Asp.Net Mvc 中使用 Ajax 刷新表列表

html - CSS:设置div的背景颜色填充

jquery - 使用 jquery 滑动对象

javascript - jQuery - 通过文本描述设置选择控件的选定值