JQuery center a div in the middle of the page

JQuery center a div in the middle of the page

I working on a  Lightbox (tutorial) , a div container wich open on click. 
This div container isn“t displayed and is located under the click element.
Now i tried to center it vertical but withouth success.

  1. $(window).resize(function() {
  2.   $(".modal-box").css({
  3.     top: (($(window).height()  - $(".modal-box").outerHeight() / 2) + $(window).scrollTop() + "px")  
  4.   });
  5. });

The problem is: At the beginning the div is almost out of the bottem screen and divs below gone out of top screen.
I would have each div in the middle of the screen, no matter of the position.