【问题标题】:overlay center position not working覆盖中心位置不起作用
【发布时间】:2012-05-30 11:28:53
【问题描述】:

我使用 jQuery 工具来实现叠加效果。 这听起来很奇怪,但是当第一次打开叠加层时,它并没有像预期的那样居中,而是一直位于左侧。 如果我关闭链接并再次打开它,这次它是居中的?? 不知道这里发生了什么......

$(function() {
        $("a[rel]").overlay({ 
            mask: '#000',
            top: 'center', 
            left: 'center',
            onBeforeLoad: function() {
                // grab wrapper element inside content
                var wrap = this.getOverlay().find(".contentWrap");
                // load the page specified in the trigger
                wrap.load(this.getTrigger().attr("href"), function(){initialize();});
            }
        });
    }); 
<a href="default.cs.asp?Process=ViewCheckinMap" rel="#overlay">clik to map</a>
<!-- overlayed element -->
<div class="apple_overlay" id="overlay">
  <!-- the external content is loaded inside this tag -->
  <div class="contentWrap"></div>
</div>
<style>
  /* use a semi-transparent image for the overlay */
  #overlay {
    background-image:url(/media/img/overlay/transparent.png);
    color:#efefef;
    height:450px;
  }
  /* container for external content. uses vertical scrollbar, if needed */
  div.contentWrap {
    height:400px;
    width:960px;
    background: #FFF;
  }
</style>

【问题讨论】:

  • 什么是jsfiddle,以前没听说过?
  • 我在 jsfiddle 没有收到错误。

标签: jquery css jquery-tools


【解决方案1】:

您只需将#overlay 设为相对位置并添加设置宽度:

#overlay {
    position:relative;
    width:480px;
}

宽度可以随心所欲,但确实需要宽度。

【讨论】:

    猜你喜欢
    • 2021-01-15
    • 1970-01-01
    • 2020-08-08
    • 2016-05-14
    • 2015-08-13
    • 1970-01-01
    • 2011-03-24
    • 2014-04-03
    • 1970-01-01
    相关资源
    最近更新 更多