I need to put a div element in the center of the screen. I found a simple code below, but I need the center of the ACTUAL screen, not the "total height / 2" page!
here is the jQuery code that centers the element but not the actual screen;
jQuery.fn.center = function () { this.css("position","absolute"); this.css("top", ( $(window).height() - this.height() ) / 2+$(window).scrollTop() + "px"); this.css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px"); return this;}
as I said, I need to calculate the actual screen sizes (for example, 1366 * 768 or any other users who have resized their browsers) and place the element in the center of the screen. therefore, if I scroll down the page, the always centered div should again be in the center.
Said Bahadır Kaya
source share