This example describes the jquery plug-in implementation to control the dynamic center of the page element display method. Share to everyone for your reference. The implementation method is as follows:
(function ($) {$.fn._center = function (self, parent, dimension) {if (!dimension.vertical &&!dimension.ho Rizontal) 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) + $ (par
ENT). 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);
I hope this article will help you with your jquery programming.