Я полностью работаю с циклом анимации, когда вы щелкаете по нему, но как я могу сделать тот же эффект переключения при нажатии A ?.Тот же эффект переключения назад и форте.Большое вам спасибо.
Похоже, ваш пост в основном кодовый;пожалуйста, добавьте некоторые подробности. Похоже, что ваш пост в основном код;пожалуйста, добавьте больше деталей.
DEMO: https://jsfiddle.net/rihotzu/nywbvxqd/1/#
HTML
<!doctype <!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>sprite test</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="default"></div>
</body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="script.js" charset="utf-8"></script>
</html>
CSS:
body {
background-color: black;
margin: 0;
padding: 0;
}
.default{
cursor: pointer;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: calc(10361px / 11);
height: 210px;
background: url(https://i.imgur.com/sz8vhOh.jpg);
animation: open 0.5s steps(11);
animation-fill-mode: forwards;
animation-play-state: paused;
}
.default2{
cursor: pointer;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: calc(10361px / 11);
height: 210px;
background: url(https://i.imgur.com/sz8vhOh.jpg);
animation: open 0.5s steps(11);
animation-fill-mode: forwards;
animation-play-state: running;
}
.back{
cursor: pointer;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: calc(10361px / 11);
height: 210px;
background: url(https://i.imgur.com/sz8vhOh.jpg);
animation: close 0.5s steps(11);
animation-fill-mode: forwards;
animation-play-state: running;
}
@keyframes open
{
from
{
background-position: 0;
}
to
{
background-position: -10361px;
}
}
@keyframes close
{
from
{
background-position: -10361px;
}
to
{
background-position: 0;
}
}
JS:
$('.default').click(function() {
$(this).removeClass('default');
$(this).addClass('default2');
$('.default2').click(function() {
$(this).removeClass('default2');
$(this).addClass('back');
$('.back').click(function() {
$(this).toggleClass('back');
$(this).toggleClass('default2');
});
});
});