jQuery 兼容ie6的固定定位插件

时间:2014-01-29所属栏目: Html+css 来源: 热度:

插件:

 (function($) {
$.fn.extend({
position : function(center) {
var left = 0, top = 0;
if (center) {
left = ($(window).width() - $(this).outerWidth(true)) / 2;
top = ($(window).height() - $(this).outerHeight(true)) / 2;
} else {
if ($(this).css("left") !== 'auto') {
left = parseInt($(this).css("left"));
} else if ($(this).css("right") !== 'auto') {
left = $(window).width() - $(this).outerWidth(true) - parseInt($(this).css("right"));
}
if ($(this).css("top") !== 'auto') {
top = parseInt($(this).css("top"));
} else if ($(this).css("bottom") !== 'auto') {
top = $(window).height() - $(this).outerHeight(true) - parseInt($(this).css("bottom"));
}
}
return $(this).css({ top : top, left : left, bottom : 'auto', right : 'auto' });
},
fixed : function () {
var left = parseInt($(this).css("left")), top = parseInt($(this).css("top"));
return ($.browser.msie && parseFloat($.browser.version) > 6.0)
? this.css({position : 'fixed'})
: this.each(function(i,o) {
var $this = $(this).css({position : 'absolute', top : top});
setInterval(function() { $this.css({ top : $().scrollTop() + top }); }, 1);
});
}
});
})(jQuery);  

测试:

Demo
标签:
评论列表(网友评论仅供网友表达个人看法,并不表明本站同意其观点或证实其描述)