-
Notifications
You must be signed in to change notification settings - Fork 3
/
modal.html
74 lines (60 loc) · 1.93 KB
/
modal.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<html>
<head>
<style>
.modals-container {
position: absolute;
width: 100%;
height: 100%;
left: 0;
top: 0;
visibility: hidden;
}
.modals-container.modal-container-active {
visibility: visible;
}
.modals-container div {
background-color: grey;
height: 200px;
position: absolute;
top: 10px;
width: 94%;
margin-left: 3%;
margin-right: 3%;
opacity: 0; /* hide all modals that are not active by default */
transition: opacity 300ms;
}
/* only show the modals with the active class applied. */
.modals-container div.modal-active {
opacity: 1;
z-index: 1;
}
</style>
</head>
<body>
<p>Interact with the modal by clicking on the button below</p>
<button class="show-btn">Show Modal</button>
<!-- create an empty container for all of our modals -->
<div class="modals-container"></div>
<script src="../dist/modal.js"></script>
<script>
// build your modal content
var modalEl = document.createElement('div');
modalEl.innerHTML = '<p>The world\'s simplest modal is showing!</p><button class="close-btn">Close Modal</button>';
var closeButton = modalEl.getElementsByClassName('close-btn')[0];
var showButton = document.getElementsByClassName('show-btn')[0];
// start your modal instance
var modal = new Modal.default(modalEl, {
containerEl: document.getElementsByClassName('modals-container')[0],
activeClass: 'modal-active'
});
// when the show button is clicked, show modal.
showButton.addEventListener('click', function () {
modal.show();
});
// when the close button is clicked, hide modal.
closeButton.addEventListener('click', function () {
modal.hide();
});
</script>
</body>
</html>