Skip to content

Commit ff20a18

Browse files
authored
Fixing gallery modal size and background scrolling (#1169)
* the modal is fixed, thanks colby * deleting the inline CSS for overflow on hide
1 parent 1e30cde commit ff20a18

File tree

3 files changed

+28
-38
lines changed

3 files changed

+28
-38
lines changed

gallery.html

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@
1717
<link href="https://fonts.googleapis.com/css2?family=Roboto&display=swap" rel="stylesheet">
1818
</head>
1919
<body>
20-
<div id="modal">
21-
<i class="fas fa-times" id="close-modal"></i>
22-
<img id="modal-img" src="https://images.unsplash.com/photo-1567309254107-5babef35b7b4?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=1351&q=80" alt="image"/>
20+
<div id="modal-container">
21+
<div id="modal">
22+
<i class="fas fa-times" id="close-modal"></i>
23+
<img id="modal-img" src="https://images.unsplash.com/photo-1567309254107-5babef35b7b4?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=1351&q=80" alt="image"/>
24+
</div>
2325
</div>
24-
<div id="modal-background"></div>
2526
<nav>
2627
<div id="mobile-menu">
2728
<i class="fas fa-bars" id="toggler"></i>

gallery.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,25 +62,27 @@ function viewAlbum(albumName) {
6262
// Opening modal
6363
$(document).on('click', function(event) {
6464
if ($(event.target).hasClass('image')) {
65-
$('#modal').show();
66-
var top = 'calc(5% + ' + (window.scrollY) + 'px)';
6765
var fullUrl = $(event.target).attr('data-bg').replaceAll('/thumb/', '/full/');
6866
$('#modal-img').attr('src', fullUrl);
69-
$('#modal').css('top', top);
70-
$('#modal-background').show();
67+
$('#modal-container').css('display', 'flex');
68+
$('html').css('overflow', 'hidden');
7169
}
7270
});
7371

7472
// Closing modal with x
7573
$('#close-modal').on('click', function() {
76-
$('#modal').hide();
77-
$('#modal-background').hide();
74+
$('#modal-container').hide();
75+
$('html').css('overflow', '');
76+
});
77+
78+
$('#modal').on('click', function(event) {
79+
event.stopPropagation();
7880
});
7981

8082
// Closing modal with background
81-
$('#modal-background').on('click', function() {
82-
$('#modal').hide();
83-
$('#modal-background').hide();
83+
$('#modal-container').on('click', function(event) {
84+
$('#modal-container').hide();
85+
$('html').css('overflow', '');
8486
});
8587

8688
// Navbar functionality

sass/gallery.scss

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,18 @@ p {
123123
}
124124
}
125125

126-
#modal-background {
126+
#modal-container {
127127
background-color: rgba(black, 85%);
128128
width: 100%;
129129
height: 100%;
130130
position: fixed;
131+
padding: 25px;
131132
z-index: 2;
132133
display: none;
134+
justify-content: center;
135+
align-items: center;
133136
top: 0;
137+
overflow: auto;
134138
cursor: pointer;
135139
}
136140

@@ -139,22 +143,20 @@ p {
139143
background-color: $off-white;
140144
border-radius: 20px;
141145
padding-top: 50px;
142-
top: 10%;
146+
position: relative;
147+
max-width: 100%;
148+
max-height: 100%;
143149
margin: auto;
144-
width: auto;
145-
left: 50%;
146-
transform: translateX(-50%);
147-
max-height: 90%;
148-
position: absolute;
149150
z-index: 3;
150-
display: none;
151+
display: block;
152+
cursor: default;
151153

152154
img {
153155
display: block;
154-
max-width: 100%;
155-
max-height: calc(90vh - 40px); // 40px from the padding of modal (20 top + 20 bottom)
156156
width: auto;
157157
height: auto;
158+
max-width: 100%;
159+
max-height: 100%;
158160
border: 8px solid $off-white;
159161
border-top: none;
160162
border-radius: 20px;
@@ -187,21 +189,6 @@ p {
187189
.image-container {
188190
grid-template-columns: repeat(2, 1fr);
189191
}
190-
191-
#modal {
192-
width: 90%;
193-
max-height: none;
194-
padding-top: 40px;
195-
196-
img {
197-
width: 100%;
198-
max-height: none;
199-
}
200-
}
201-
202-
#close-modal {
203-
font-size: 30px;
204-
}
205192
}
206193

207194
@media screen and (max-width: 660px) {

0 commit comments

Comments
 (0)