you can use it this way
// Set the modal block in the center of the page
jQuery.fn.center = function () { this.css("position","absolute"); this.css("top", ( jQuery(window).height() - this.height() ) / 2+jQuery(window).scrollTop() + "px"); this.css("left", ( jQuery(window).width() - this.width() ) / 2+jQuery(window).scrollLeft() + "px"); return this; }
// then call the function
jQuery(".modal-profile").center();
and this will make your code organized and easy to use in any project for a modal center. you can view this work in another question
modal appears on page load
arifur rahman
source share