<div id="block">Тицяй, щоб уввімкнути або зупинити анімацію</div>
#block {
font-family: monospace;
background-color: gold;
color: #222;
font-size: 16px;
line-height: 1.45;
width: 175px;
text-align: center;
padding: 36px 16px;
box-shadow: 1px 1px 1px 1px #000;
cursor: pointer;
transition: box-shadow .15s linear;
position: absolute;
top: 16px;
left: 16px;
animation: move 1.15s ease-in 0s infinite alternate paused none;
}
#block:hover {
box-shadow: 1px 1px 1px 1px rgba(0, 0, 0, .45);
}
@keyframes move {
from {
top: 16px;
left: 16px;
}
to {
top: 250px;
left: 350px;
}
}
document.getElementById('block').onclick = function() {
if ( this.style.animationPlayState != 'running' ) {
this.style.animationPlayState = 'running';
} else {
this.style.animationPlayState = 'paused';
}
}
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.