Skip to content

Commit 89cfb30

Browse files
committed
Add four-sided positioning with scale() demo.
1 parent 7d3e0fd commit 89cfb30

File tree

3 files changed

+138
-0
lines changed

3 files changed

+138
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ with.
1010

1111
## My JavaScript Demos - I Love JavaScript!
1212

13+
* [Four-Sided Positioning Plays Nicely With Scale() Transformations In CSS](https://bennadel.github.io/JavaScript-Demos/demos/four-sided-scale/)
1314
* [Organizing My Application Layers Using Z-Index Stacking Contexts In CSS](https://bennadel.github.io/JavaScript-Demos/demos/z-index-layers/)
1415
* [Code Kata: Water Breathing Exercise In JavaScript](https://bennadel.github.io/JavaScript-Demos/demos/water-breathing/)
1516
* [Tracking User Interactions And Analytics With Small Abstractions In AngularJS](https://bennadel.github.io/JavaScript-Demos/demos/tracking-user-interactions-angularjs/)

demos/four-sided-scale/demo.css

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
body {
3+
font-family: sans-serif ;
4+
font-size: 18px ;
5+
}
6+
7+
a.toggle {
8+
color: red ;
9+
cursor: pointer ;
10+
text-decoration: underline ;
11+
}
12+
13+
.modal {
14+
background-color: #333333 ;
15+
}
16+
17+
.modal::before {
18+
border: 2px solid #cccccc ;
19+
border-radius: 14px 14px 14px 14px ;
20+
bottom: 10px ;
21+
content: "" ;
22+
left: 10px ;
23+
pointer-events: none ;
24+
position: absolute ;
25+
right: 10px ;
26+
top: 10px ;
27+
}
28+
29+
.modal a.toggle {
30+
align-items: center ;
31+
bottom: 0px ;
32+
color: white ;
33+
display: flex ;
34+
justify-content: center ;
35+
left: 0px ;
36+
position: absolute ;
37+
right: 0px ;
38+
top: 0px ;
39+
}

demos/four-sided-scale/index.htm

+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<title>
6+
Four-Sided Positioning Plays Nicely With Scale() Transformations In CSS
7+
</title>
8+
<link rel="stylesheet" type="text/css" href="./demo.css">
9+
<style type="text/css">
10+
11+
.modal {
12+
/* Four-sided positioning. */
13+
bottom: 0px ;
14+
left: 0px ;
15+
position: fixed ;
16+
right: 0px ;
17+
top: 0px ;
18+
19+
/*
20+
Animating the modal element into view: our modal-enter keyframes are
21+
going to use SCALE() (and opacity) to gradually transition the modal
22+
element into its fixed position layout.
23+
*/
24+
animation-duration: 1s ; /* NOTE: Absurdly SLOW for demo purposes. */
25+
animation-fill-mode: both ;
26+
animation-iteration-count: 1 ;
27+
animation-name: modal-enter ;
28+
animation-timing-function: ease-out ;
29+
}
30+
31+
@keyframes modal-enter {
32+
from {
33+
opacity: 0 ;
34+
transform: scale( 0.7 ) ;
35+
}
36+
to {
37+
opacity: 1 ;
38+
transform: scale( 1.0 ) ;
39+
}
40+
}
41+
42+
</style>
43+
</head>
44+
<body>
45+
46+
<h1>
47+
Four-Sided Positioning Plays Nicely With Scale() Transformations In CSS
48+
</h1>
49+
50+
<p>
51+
<a class="toggle">Open modal</a>
52+
</p>
53+
54+
<!--
55+
This modal window will use FIXED positioning and have a four-sided (top, right,
56+
bottom, left) arrangement. It will also fade into view using CSS transitions.
57+
-->
58+
<template>
59+
<div class="modal">
60+
<a class="toggle">Close modal</a>
61+
</div>
62+
</template>
63+
64+
65+
<!-- Load scripts. -->
66+
<script type="text/javascript" src="../../vendor/jquery/3.6.0/jquery-3.6.0.min.js"></script>
67+
<script type="text/javascript">
68+
69+
var modal = null;
70+
var template = $( "template" );
71+
72+
// We'll use event-delegation so that we can capture the click event in the
73+
// modal, which isn't even rendered yet.
74+
$( document ).on( "click", ".toggle", toggleModal );
75+
76+
// I show / hide the modal window by adding it to or removing it from the DOM
77+
// (Document Object Model) tree, respectively.
78+
function toggleModal() {
79+
80+
if ( modal ) {
81+
82+
modal.remove();
83+
modal = null;
84+
85+
} else {
86+
87+
modal = $( template.prop( "content" ).firstElementChild.cloneNode( true ) )
88+
.appendTo( document.body )
89+
;
90+
91+
}
92+
93+
}
94+
95+
</script>
96+
97+
</body>
98+
</html>

0 commit comments

Comments
 (0)