2013-09-27 84 views
0

我收到了一些以网页中间的div为中心的代码。该代码在Chrome上效果很好,但出于某种原因,在IE上(我认为它是9或10),它第一次工作,然后它不。Internet Explorer中心DIV问题

为了说明这个问题,这里有一些照片:(忽略你不明白的迹象,这就是我的语言)

铬:

enter image description here

IE我第一次点击的对象开拓:

enter image description here

IE第二时间以上,当我点击一个objec吨至打开:

enter image description here

这是我使用居中DIV代码:

jQuery.fn.center = function() 
{ 
    this.css("position","fixed"); 
    this.css("top", ($(window).height()/2) - (this.outerHeight()/2)); 
    this.css("left", ($(window).width()/2) - (this.outerWidth()/2)); 
    return this; 
} 

使用该center()函数的代码:

$('#products,#search-result').on("click",'.product-item-info',function() { 
    var pid = $(this).find('input').val(); 
    $.get('product_info.php',{pid:pid},function(data){ 
     $('#product-lb').html(data).append('<span class="x"><span>X</span></span>'); 
     $('.x').click(function() { 
      $('#dimmer').click(); 
     }); 

     $('#dimmer').css({width:$('html').width(),height:$('html').height()}); 
     $('#product-lb').center(); 
     $('#product-lb').show(800); 
     $('#dimmer').show(); 
     $(window).resize(function() { 
      $('#product-lb').center(); 
     }); 
    }); 
}); 

解释: #products是包含所有彩色div的div以蓝色和绿色显示,如图所示 .product-item-info是可以在每个产品DIV中找到的矩形类。 #dimmer是黑色背景 #product-lb是具有为中心,并在页面

上显示的DIV我希望这是足够的信息!如果您需要更多,请随时询问。

提前致谢!

+0

你能摆弄这一个或提供一个链接到您的网站? –

+0

@GaneshPandhere我会发布一个链接到一个demontration网站。出于某种原因,我的主人在这个地方遇到了困难,所以它还需要几分钟的时间。 – kfirba

+0

@GaneshPandhere不幸的是,我的共享IP地址似乎在DDOS攻击下,因此,共享IP地址被过滤,这将需要一段时间,因为我可以在这里发布链接。 – kfirba

回答

-2

如果您已经使用jQuery,为什么不使用jQueryUI作为对话框?

无论如何,如果你想要去的正常方式why not use the awesome position:absolute method?

这也适用于一个div并与IE7 +兼容,这个是一个唯一的CSS-件事的加分。

+0

divs高度未知。因此,必须使用固定位置或绝对位置。如果没有理由使用它,我不想为此使用jQueryUI – kfirba