the machine elf and Stefan Kendall are both very close, but both are incomplete, so you simply combine them like this (the machine elf did not take into account the scroll bars, and Setfan did not take into account the height and width of the div itself):
Assuming your id for your div is "myDiv"
$('#myDiv').css('position','fixed');
$('#myDiv').css("left", ($(window).width()/2-$('#myDiv').width()/2) + "px");
$('#myDiv').css("top", ($(window).height()/2-$('#myDiv').height()/2) + "px"));
You may also need to set the css of your div to the height and width of the patch, and its display is set to "block". You can do this with jQuery.
In addition, you can combine all this into one long string.
source
share