jQuery插件实现控制网页元素动态居中显示
本文实例讲述了jQuery插件实现控制网页元素动态居中显示的方法。分享给大家供大家参考。具体实现方法如下:
(function($)
{
$.fn._center=function(self,parent,dimension)
{
if(!dimension.vertical&&!dimension.horizontal)
return;//won'tdoanythinganyway
if(parent)
parent=self.parent();
else
parent=window
self.css("position","absolute");
if(dimension.vertical)
{
self.css("top",Math.max(0,(($(parent).height()-$(self).outerHeight())/2)+
$(parent).scrollTop())+"px");
}
if(dimension.horizontal)
{
self.css("left",Math.max(0,(($(parent).width()-$(self).outerWidth())/2)+
$(parent).scrollLeft())+"px");
}
returnself;
};
$.fn.center=function(parent,args)
{
if(!args)
{
args={horizontal:true,vertical:true};
}
returnthis.each(function()
{
varobj=$(this);
obj._center(obj,parent,args);
functioncallback()
{
obj._center(obj,parent,args);
}
callback();
$(window).resize(callback);
});
};
})(jQuery);
希望本文所述对大家的jQuery程序设计有所帮助。
热门推荐
10 祝孙辈生日祝福语简短
11 恋人跨年祝福语大全简短
12 考大学敬酒简短祝福语
13 开工投产大吉祝福语 简短
14 偶然结婚祝福语朋友简短
15 感谢学长学姐祝福语简短
16 戏精的祝福语简短
17 我要结婚祝福语简短
18 婚前女儿生日祝福语简短