Skip to content

Instantly share code, notes, and snippets.

@ursuleacv
Created August 23, 2013 14:46
Show Gist options
  • Save ursuleacv/6320146 to your computer and use it in GitHub Desktop.
Save ursuleacv/6320146 to your computer and use it in GitHub Desktop.
Modal pop up window to fit within browser view if resize height
$(function(){
$(window).resize(function(){
// get the screen height and width
var maskHeight = $(window).height();
var maskWidth = $(window).width();
// calculate the values for center alignment
var dialogTop = (maskHeight - $('#dialog-box').height())/2;
var dialogLeft = (maskWidth - $('#dialog-box').width())/2;
// assign values to the overlay and dialog box
$('#dialog-overlay').css({ height:$(document).height(), width:$(document).width() }).show();
$('#dialog-box').css({ top: dialogTop, left: dialogLeft, position:"fixed"}).show();
}).resize();
});
http://jsfiddle.net/tF8TU/2/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment