-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimage fade.html
More file actions
190 lines (170 loc) · 5.4 KB
/
image fade.html
File metadata and controls
190 lines (170 loc) · 5.4 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
<!DOCTYPE html>
<html lang="en">
<head>
<style type="text/css">
body, html {
margin: 0;
height: 100%;
font-family: sans-serif;
}
#image-wrapper {
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
z-index: 1; /* Lower than the UI */
}
#image-wrapper img {
position: absolute;
z-index: 1;
width: 100%;
height: 100%;
object-fit: cover;
}
#image-wrapper img.active{
z-index:3;
}
/* Positioning the Pause Button at the top */
.pause-container {
position: fixed;
top: 20px;
left: 20px;
z-index: 2000; /* Ensure it is above everything */
background: white;
opacity: 0.8;
padding: 10px;
border-radius: 8px;
display: flex;
align-items: center;
gap: 10px;
}
.center {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
border-radius: 25px;
border: 2px solid #DEDEDE;
height: 320px;
width: 500px;
padding: 20px;
box-sizing: border-box;
overflow: hidden;
z-index: 1000;
background-color: white;
text-align: center;
}
h1 {
text-align: center;
}
/* Switch Styling */
.switch {
position: relative;
display: inline-block;
width: 60px;
height: 34px;
}
.switch input {
opacity: 0;
width: 0;
height: 0;
}
.slider {
border-radius: 34px;
position: absolute;
cursor: pointer;
top: 0; left: 0; right: 0; bottom: 0;
/* Contrast Enhancement: Darkened the gray from #ccc to #595959 */
background-color: #595959;
transition: .4s;
border: 1px solid #000; /* Added border for shape definition */
}
.slider:before {
border-radius: 50%;
position: absolute;
content: "";
height: 26px;
width: 26px;
left: 4px;
bottom: 3px;
background-color: white;
transition: .4s;
box-shadow: 0 2px 4px rgba(0,0,0,0.4);
}
input:checked + .slider {
background-color: #0056b3;
}
input:checked + .slider:before {
transform: translateX(26px);
}
/* --- KEYBOARD FOCUS INDICATION --- */
/* This adds a thick blue ring around the slider when tabbing */
input:focus-visible + .slider {
outline: 3px solid #FFD700; /* Gold outline for high visibility */
outline-offset: 3px;
box-shadow: 0 0 0 6px rgba(0, 0, 0, 0.2);
}
</style>
</head>
<body>
<div class="pause-container">
<label for="pause-input">Pause Animation</label>
<label class="switch">
<input type="checkbox" id="pause-input">
<span class="slider"></span>
</label>
</div>
<div id="image-wrapper">
<img class="active" src="https://raw.githubusercontent.com/robmc/robmc.github.io/refs/heads/master/images/dusk.jpg" alt="" />
<img src="https://raw.githubusercontent.com/robmc/robmc.github.io/refs/heads/master/images/night.jpg" alt="" />
</div>
<div class="center">
<h1>Pause/Stop/Hide</h1>
<p>Testing the ability to pause/stop animations. The background image has an update animation every 7 seconds. This is testing to meet <a href="https://www.w3.org/WAI/WCAG21/Understanding/pause-stop-hide.html">WCAG Success Criteria 2.2.2 Pause, Stop, Hide</a>.</p>
<footer>
<a href="http://robertjmccaffery.com/examples.html">Back to Examples</a> | <a href="http://robertjmccaffery.com/">Home</a>
</footer>
</div>
<script src="https://code.jquery.com/jquery-4.0.0.js" integrity="sha256-9fsHeVnKBvqh3FB2HYu7g2xseAZ5MlN6Kz/qnkASV8U=" crossorigin="anonymous"></script>
<script>
$(document).ready(function() {
let imageTimer;
function cycleImages() {
// If the pause input is checked, do nothing and don't schedule the next run
if ($('#pause-input').is(':checked')) {
return;
}
var $active = $('#image-wrapper .active');
var $next = ($active.next().length > 0) ? $active.next() : $('#image-wrapper img:first');
$next.css('z-index', 2);
$active.fadeOut(1500, function() {
$active.css('z-index', 1).show().removeClass('active');
$next.css('z-index', 3).addClass('active');
});
}
// Function to start the interval
function startAnimation() {
if (!imageTimer) {
imageTimer = setInterval(cycleImages, 7000);
}
}
// Function to stop the interval
function stopAnimation() {
clearInterval(imageTimer);
imageTimer = null;
}
// Listen for toggle changes
$('#pause-input').on('change', function() {
if ($(this).is(':checked')) {
stopAnimation();
} else {
startAnimation();
}
});
// On by default: start the animation immediately
startAnimation();
});
</script>
</body>
</html>