jquery插件 div居中
寫的一個簡單的jquery插件,在IE6.0下,自動把div 的position 屬性改為absolute。
jQuery.fn.extend({
juzhong:function(){
var p={};//在ie瀏覽器下用top left 和標簽相同的做變量,會出問題
h=$(this).height();
w=$(this).width();
p.top =($(window).height()-h)/2;
p.left=($(window).width()-w)/2;
if($.browser.msie && $.browser.version=='6.0'){//兼容IE6.0
$(this).css('position','absolute');
p.top=p.top+$(document).scrollTop();
p.left=p.left+$(document).scrollLeft();
//alert('position:absolute');
}else{
$(this).css('position','fixed');
}
$(this).css("left",p.left+'px');
$(this).css("top",p.top+'px');
}
});
浙公網安備 33010602011771號