Home > Web Front-end > JS Tutorial > 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
Release: 2016-05-16 18:33:47
Original
1154 people have browsed it
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();
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template