Skip to content

Instantly share code, notes, and snippets.

@mtairu
Created November 27, 2016 20:52
Show Gist options
  • Save mtairu/b9410e86c9c210927763937b403024a7 to your computer and use it in GitHub Desktop.
Save mtairu/b9410e86c9c210927763937b403024a7 to your computer and use it in GitHub Desktop.
$(document).ready(function () {
//open popup
$(".pop").click(function () {
$(this).parent().find("form .overlay_form").fadeIn(1000);
positionPopup();
});
//close popup
$(".close").click(function () {
$(".overlay_form").fadeOut(500);
});
});
//position the popup at the center of the page
function positionPopup() {
if (!$(".overlay_form").is(':visible')) {
return;
}
$(".overlay_form").css({
left: ($(window).width() - $('.overlay_form').width()) / 2,
top: ($(window).width() - $('.overlay_form').width()) / 7,
position: 'absolute'
});
}
//maintain the popup at center of the page when browser resized
$(window).bind('resize', positionPopup);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment