Please see below script.
$.fn.doCenter = function () {
var topVal = (($(window).height() - this.outerHeight()) / 2) + $(window).scrollTop();
var leftVal = (($(window).width() - this.outerWidth()) / 2) + $(window).scrollLeft();
if (topVal < 0) topVal = 0;
if (leftVal < 0) leftVal = 0;
this.css("position","absolute");
this.css("top", topVal + "px");
this.css("left", leftVal + "px");
return this;
}
Sample usage:
$("#yourmodal").doCenter();
Give it a try, you will love it!!
No comments:
Post a Comment