Hi there LarryJohnson,
How about using CSS instead of JavaScript?
Here is an example...
Code:
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,height=device-height,initial-scale=1">
<title>Page Shaker</title>
<!--
The internal CSS should be transferred to an external file
<link rel="stylesheet" href="screen.css" media="screen">
-->
<style media="screen">
* {
padding: 0;
margin: 0;
box-sizing: border-box;
}
html, body {
height: 100%;
background-color: #f0f0f0;
font: normal 1em / 1.5em sans-serif;
}
#container {
display: flex;
flex-direction: column;
justify-content: center;
height:100%;
padding:1em;
}
h1 {
color: #555;
font-weight: normal;
text-align: center;
text-transform: capitalize;
text-shadow: 2px 2px 2px rgba( 0, 0, 0, 0.4 );
}
input {
position: absolute;
left: -999em;
}
input:checked + #container {
animation: shake 1s 1s infinite;
}
input:checked + #container label {
background-color: #f00;
}
input:checked + #container label::before {
content: 'stop';
}
#container label {
display: flex;
justify-content: center;
width: 100%;
max-width: 15em;
padding: 1em;
margin: auto;
border: 1px solid #000;
border-radius: 0.75em;
background-color: #0f0;
box-shadow: 0.3em 0.3em 0.3em rgba( 0, 0, 0, 0.4 );
font-size: 2em;
cursor: pointer;
transition: 1s ease-in-out;
}
#container label::before {
content: 'start';
margin-right: 0.5em;
}
@keyframes shake {
0% { margin: 0; }
10% { margin: -2px 0 0 -2px; }
20% { margin: 0; }
30% { margin: -2px 0 0 -2px; }
40% { margin: 0;}
50% { margin: -2px 0 0 -2px; }
60% { margin: 0; }
70% { margin: -2px 0 0 -2px; }
80% { margin: 0; }
90% { margin: -2px 0 0 -2px; }
100% { margin: 0; }
}
</style>
</head>
<body>
<input type="checkbox" id="cb">
<div id="container">
<h1>a little page shaker</h1>
<label for="cb">shake</label>
</div>
</body>
</html>
You can see a
Demo here...
A little page shaker
coothead
Last edited by coothead; 05-14-2021 at 11:28 AM.
~ the original bald headed old fart ~
Bookmarks