Skip to content

Instantly share code, notes, and snippets.

@tedshd
Last active December 16, 2015 02:50
Show Gist options
  • Select an option

  • Save tedshd/b079ac415563ed7e2433 to your computer and use it in GitHub Desktop.

Select an option

Save tedshd/b079ac415563ed7e2433 to your computer and use it in GitHub Desktop.
responsive popup demo
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>responsive popup</title>
<link rel="stylesheet" href="http://meyerweb.com/eric/tools/css/reset/reset200802.css">
<style>
html, body {
width: 100%;
height: 100%;
}
.hide {
display: none;
}
.popup_open {
overflow-y: hidden;
}
.popup {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
min-width: 1200px;
min-height: 100%;
background: rgba(0,0,0,.7);
}
.content {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
margin: auto;
width: 1200px;
height: 90%;
}
.hd {
z-index: 1;
position: absolute;
top: 0;
left: 0;
width: 100%;
}
.bd {
z-index: 0;
position: absolute;
top: 0;
left: 0;
width: 100%;
/*height: calc(100% - 3em);*/
height: 100%;
border-top: solid 2em #ccc;
border-bottom: solid 2em #ccc;
border-left: solid 2em #ccc;
border-right: solid 2em #ccc;
box-sizing: border-box;
overflow-y: auto;
background: #fff;
}
.ft {
z-index: 1;
position: absolute;
bottom: 0;
left: 0;
width: 100%;
}
</style>
</head>
<body>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
<a href="javascript:void(0)">Click</a>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
haha<br>
<div class="popup hide">
<div class="content">
<div class="hd">TITLE</div>
<div class="bd">
test
<br><br><br><br><br><br><br><br><br><br><br>
test ahah
test
<br><br><br><br><br><br><br><br><br><br><br>
test ahah
test
<br><br><br><br><br><br><br><br><br><br><br>
test ahah
test
<br><br><br><br><br><br><br><br><br><br><br>
test ahah
</div>
<div class="ft"><button>submit</button></div>
</div>
</div>
</body>
<script>
document.querySelector('a').addEventListener('click', function () {
var top = window.pageYOffset;
document.querySelectorAll('.popup')[0].classList.remove('hide');
document.querySelectorAll('.popup')[0].setAttribute('style', 'top:' + top + 'px');
document.body.classList.add('popup_open');
});
document.querySelectorAll('.popup')[0].addEventListener('click', function () {
document.querySelectorAll('.popup')[0].classList.add('hide');
document.body.classList.remove('popup_open');
});
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment