Home  >  Article  >  Web Front-end  >  JQuery code to display elements in the center of the screen_jquery

JQuery code to display elements in the center of the screen_jquery

WBOY
WBOYOriginal
2016-05-16 18:33:471098browse
Copy code The code is as follows:

(function($){
$.fn.center = function(){
var top = ($(window).height() - this.height())/2;
var left = ($(window).width() - this.width() )/2;
var scrollTop = $(document).scrollTop();
var scrollLeft = $(document).scrollLeft();
return this.css( { position : 'absolute', ' top' : top scrollTop, left : left scrollLeft } ).show();
}
})(jQuery)



Calling method:
Copy code The code is as follows:

$('#dialog').center();
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn