Skip to content

Instantly share code, notes, and snippets.

@kirilkirkov
Created July 17, 2015 13:41
Show Gist options
  • Save kirilkirkov/48256e632527552e173e to your computer and use it in GitHub Desktop.
Save kirilkirkov/48256e632527552e173e to your computer and use it in GitHub Desktop.
ReSizable popup with cookies for one time opening
<html>
<head>
<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
</head>
<body>
<!-- Popup -->
<div id="overlay" style="display:none; position: fixed; width: 100%; height: 100%; background-color: black; z-index:1101; opacity:0.7; filter: alpha(opacity=70); top:0; left:0;"></div>
<div id="popup" style="display:none; z-index:1101; position: fixed; width:100%; max-width:700px; height:100%; max-height:572px; top: 50%; left: 50%; margin-top: -286px; margin-left: -350px;">
<a href="#" style="color:#fff; float:right; font-weight:bold;" onClick="setCookie()">Close <span class="glyphicon glyphicon-remove"></span></a>
<div style="width:700px; height:572px; background-color:#000;"></div>
</div>
<script>
if(document.cookie.indexOf('splash') == -1) {
setCenterProportion();
$(window).resize(function () {
setCenterProportion();
});
$("#popup").show();
$("#overlay").show();
}
function setCookie() {
var cookie_name='splash';
var cookie_value='true';
var tomorrow = new Date();
tomorrow.setDate(tomorrow.getDate() + 1);
var cookie_expires= tomorrow.toUTCString();
document.cookie = cookie_name+"="+cookie_value+"; expires="+cookie_expires;
$("#popup").hide();
$("#overlay").hide();
}
function setCenterProportion() {
var w = $("#popup").width() / 2;
var h = $("#popup").height() / 2;
$("#popup").css({"margin-left": -w, "margin-top": -h});
}
</script>
</body>
</html>
@kirilkirkov
Copy link
Author

3333

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment