Skip to content

Commit 0405fc3

Browse files
committed
Finish popup-modal exercise
1 parent 37187c9 commit 0405fc3

File tree

4 files changed

+81
-62
lines changed

4 files changed

+81
-62
lines changed

animation/03-pop-up/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,28 @@
11
# Popup
22

3+
Popup modals are great for replacing the standard window popups that we often fall back on when we want our users to confirm something, or log in, etc.
4+
5+
In this exercise, activate a popup modal that will appear when the user clicks on the 'Open Modal' button and disappears when they click on the 'Close Modal' button inside the popup.
6+
7+
The modal should smoothly fade in and slide up to cover the Open button. The background should darken a little to create a clear distinction between foreground and background, and a little shadow should appear on the buttons when you hover over them.
8+
9+
When you're done, keep this repo handy! Being able to build a custom modal is a great show-off for your future projects.
10+
11+
### Hints
12+
- There's a little Javascript here. Don't worry about it. It's been set up to add/remove the `show` class to the relevant elements when clicked
13+
- Multiple transitions will be required
14+
- Pay close attention to the elements being altered with classes being added or removed
15+
316
## Desired Outcome
417

518
![outcome](./desired-outcome.gif)
619

720
### Self Check
21+
22+
- The mouse cursor changes to a pointer over the buttons
23+
- A drop shadow gets added to the buttons when the mouse hovers over them
24+
- The popup modal appears when the Open button is clicked
25+
- The background fades to black with 40% opacity when the popup is opened
26+
- The popup smoothly slides up to cover the existing Open button
27+
- When the Close button is clicked the popup modal slides back down and gradually disappears
28+
- When the popup modal is hidden your mouse should not change to the pointer if hovered over an invisible Close button

animation/03-pop-up/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
66
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
77
<title>Popup</title>
8-
<link rel="stylesheet" href="index.css" />
8+
<link rel="stylesheet" href="style.css" />
99
</head>
1010
<body>
1111
<div class="button-container">

animation/03-pop-up/solution/solution.css

Lines changed: 58 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,6 @@ body {
1212
height: 100vh;
1313
background-color: #ffffff;
1414
opacity: 100%;
15-
transition: background-color 0.5s ease-in, opacity 0.5s ease-in;
16-
}
17-
18-
.button-container.show {
19-
background-color: #000000;
20-
opacity: 40%;
2115
}
2216

2317
#trigger-modal,
@@ -37,13 +31,7 @@ body {
3731
font-weight: 600;
3832
}
3933

40-
#trigger-modal:hover {
41-
cursor: pointer;
42-
box-shadow: 1px 1px 2px #000000;
43-
}
44-
45-
.popup-modal,
46-
.popup-modal.show {
34+
.popup-modal {
4735
width: 30%;
4836
height: 15%;
4937
background-color: white;
@@ -52,23 +40,8 @@ body {
5240
display: flex;
5341
justify-content: center;
5442
align-items: center;
55-
}
56-
57-
.popup-modal {
5843
margin-top: 10%;
5944
opacity: 0;
60-
visibility: hidden;
61-
transition: margin-top 0.5s ease-out, opacity 0.5s ease-out,
62-
visibility 0.5s linear;
63-
}
64-
65-
.popup-modal.show {
66-
min-height: 90px;
67-
opacity: 1;
68-
visibility: visible;
69-
margin-top: 0;
70-
transition: margin-top 0.5s ease-out, opacity 0.5s ease-out,
71-
visibility 0.5s linear;
7245
}
7346

7447
#close-modal {
@@ -80,7 +53,64 @@ body {
8053
font-weight: 600;
8154
}
8255

56+
/* SOLUTION */
57+
58+
/*
59+
Disclaimer: duplicating selectors here isn't best practice.
60+
We separated it out here to make it extra clear what has changed.
61+
*/
62+
63+
.button-container {
64+
transition: background-color 0.5s ease-in, opacity 0.5s ease-in;
65+
}
66+
67+
.button-container.show {
68+
background-color: #000000;
69+
opacity: 40%;
70+
}
71+
72+
#trigger-modal:hover,
8373
#close-modal:hover {
8474
cursor: pointer;
8575
box-shadow: 1px 1px 2px #000000;
8676
}
77+
78+
/*
79+
Keep this '.popup-modal' selector separate from the main
80+
.popup-modal selector, for the reasons outlined above
81+
.pop-up-modal.show
82+
*/
83+
.popup-modal {
84+
visibility: hidden;
85+
transition: margin-top 0.5s ease-out, opacity 0.5s ease-out,
86+
visibility 0.5s linear;
87+
}
88+
89+
/*
90+
The common properties between .popup-modal and .popup-modal.show
91+
can easily be added by just adding this selector to the main
92+
.popup-modal selector
93+
*/
94+
.popup-modal.show {
95+
width: 30%;
96+
height: 15%;
97+
background-color: white;
98+
border: 1px solid black;
99+
border-radius: 10px;
100+
display: flex;
101+
justify-content: center;
102+
align-items: center;
103+
min-height: 90px;
104+
}
105+
106+
/*
107+
Keep this selector separate from the main '.popup-modal.show'
108+
selector.
109+
*/
110+
.popup-modal.show {
111+
opacity: 1;
112+
visibility: visible;
113+
margin-top: 0;
114+
transition: margin-top 0.5s ease-out, opacity 0.5s ease-out,
115+
visibility 0.5s linear;
116+
}

animation/03-pop-up/style.css

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,6 @@ body {
1212
height: 100vh;
1313
background-color: #ffffff;
1414
opacity: 100%;
15-
transition: background-color 0.5s ease-in, opacity 0.5s ease-in;
16-
}
17-
18-
.button-container.show {
19-
background-color: #000000;
20-
opacity: 40%;
2115
}
2216

2317
#trigger-modal,
@@ -37,13 +31,7 @@ body {
3731
font-weight: 600;
3832
}
3933

40-
#trigger-modal:hover {
41-
cursor: pointer;
42-
box-shadow: 1px 1px 2px #000000;
43-
}
44-
45-
.popup-modal,
46-
.popup-modal.show {
34+
.popup-modal {
4735
width: 30%;
4836
height: 15%;
4937
background-color: white;
@@ -52,23 +40,8 @@ body {
5240
display: flex;
5341
justify-content: center;
5442
align-items: center;
55-
}
56-
57-
.popup-modal {
5843
margin-top: 10%;
5944
opacity: 0;
60-
visibility: hidden;
61-
transition: margin-top 0.5s ease-out, opacity 0.5s ease-out,
62-
visibility 0.5s linear;
63-
}
64-
65-
.popup-modal.show {
66-
min-height: 90px;
67-
opacity: 1;
68-
visibility: visible;
69-
margin-top: 0;
70-
transition: margin-top 0.5s ease-out, opacity 0.5s ease-out,
71-
visibility 0.5s linear;
7245
}
7346

7447
#close-modal {
@@ -79,8 +52,3 @@ body {
7952
border-radius: 5px;
8053
font-weight: 600;
8154
}
82-
83-
#close-modal:hover {
84-
cursor: pointer;
85-
box-shadow: 1px 1px 2px #000000;
86-
}

0 commit comments

Comments
 (0)