欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

jQuery插件實(shí)現(xiàn)控制網(wǎng)頁(yè)元素動(dòng)態(tài)居中顯示

 更新時(shí)間:2015年03月24日 10:03:09   作者:feiwen  
這篇文章主要介紹了jQuery插件實(shí)現(xiàn)控制網(wǎng)頁(yè)元素動(dòng)態(tài)居中顯示,實(shí)例分析了jQuery插件的實(shí)現(xiàn)與元素動(dòng)態(tài)顯示的技巧,需要的朋友可以參考下

本文實(shí)例講述了jQuery插件實(shí)現(xiàn)控制網(wǎng)頁(yè)元素動(dòng)態(tài)居中顯示的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:

(function($)
{
  $.fn._center = function(self, parent, dimension)
  {
    if(!dimension.vertical && !dimension.horizontal)
      return; //won't do anything anyway
    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");
    }
    return self;
  };
  $.fn.center = function(parent, args)
  {
    if(!args)
    {
      args = {horizontal: true, vertical: true};
    }
    return this.each(function()
    {
      var obj = $(this);
      obj._center(obj, parent, args);
      function callback()
      {
        obj._center(obj, parent, args);
      }
      callback();
      $(window).resize(callback);
    });
  };
})(jQuery);

希望本文所述對(duì)大家的jQuery程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論