我不确定如何描述它,所以请看这个例子:
$('button').on('click', () => {
$('.spinner').addClass('paused');
});

.spinner {
}
.spinner > div {
width: 25px;
height: 25px;
background-color: #9f9f9f;
border-radius: 100%;
display: inline-block;
-webkit-animation: sk-bouncedelay 1.4s infinite ease-in-out both;
animation: sk-bouncedelay 1.4s infinite ease-in-out both;
}
.spinner.paused > div {
-webkit-animation: sk-pause 1.4s 1 ease-in-out both;
animation: sk-pause 1.4s 1 ease-in-out both;
// -webkit-animation-play-state: paused; /* Safari 4.0 - 8.0 */
// animation-play-state: paused;
}
.spinner .bounce1 {
-webkit-animation-delay: -0.32s;
animation-delay: -0.32s;
}
.spinner .bounce2 {
-webkit-animation-delay: -0.16s;
animation-delay: -0.16s;
}
@-webkit-keyframes sk-bouncedelay {
0%, 80%, 100% { -webkit-transform: scale(0.3) }
40% { -webkit-transform: scale(1.0) }
}
@keyframes sk-pause {
80%, 100% {transform: scale(0.3)}
}
@keyframes sk-bouncedelay {
0%, 80%, 100% {
-webkit-transform: scale(0.3);
transform: scale(0.3);
} 40% {
-webkit-transform: scale(1.0);
transform: scale(1.0);
}
}

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="spinner">
<div class="bounce1"></div>
<div class="bounce2"></div>
<div class="bounce3"></div>
</div>
<button> Click </button>
&#13;
你有三个弹跳的球。当您单击该按钮时,它会添加一个暂停的类,该类将动画显示为最小的可见球。但是当你点击时,它们都会从1.0比例变为0.3比例。我希望他们从之前的州过渡到0.3。
答案 0 :(得分:1)
请看这个:
<head>
<title></title>
<style>
.spinner {
}
.spinner > div {
width: 25px;
height: 25px;
background-color: #9f9f9f;
border-radius: 100%;
display: inline-block;
-webkit-animation: sk-bouncedelay 1.4s infinite ease-in-out both;
animation: sk-bouncedelay 1.4s infinite ease-in-out both;
}
.spinner.paused > div {
-webkit-animation: sk-pause 1.4s 1 ease-in-out both;
animation: sk-pause 1.4s 1 ease-in-out both;
}
.spinner .bounce1 {
-webkit-animation-delay: -0.32s;
animation-delay: -0.32s;
}
.spinner .bounce2 {
-webkit-animation-delay: -0.16s;
animation-delay: -0.16s;
}
@-webkit-keyframes sk-bouncedelay {
0%, 80%, 100% {
-webkit-transform: scale(0.3);
}
40% {
-webkit-transform: scale(1.0);
}
}
@keyframes sk-pause {
80%, 100% {
transform: scale(0.3);
}
}
@keyframes sk-bouncedelay {
0%, 80%, 100% {
-webkit-transform: scale(0.3);
transform: scale(0.3);
}
40% {
-webkit-transform: scale(1.0);
transform: scale(1.0);
}
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
</head>
<body>
<div class="spinner">
<div id="div1" class="bounce1"></div>
<div id="div2" class="bounce2"></div>
<div id="div3" class="bounce3"></div>
</div>
<input type="button" id="a" value="Pause" />
<script>
$('#a').click(function ()
{
var computedStyle1 = window.getComputedStyle(document.getElementById("div1"));
var computedStyle1 = window.getComputedStyle(document.getElementById("div1"));
var computedStyle2 = window.getComputedStyle(document.getElementById("div2"));
var computedStyle3 = window.getComputedStyle(document.getElementById("div3"));
$('#div1').css('transform', computedStyle1.transform).css('-webkit-transform', computedStyle1.transform);
$('#div2').css('transform', computedStyle2.transform).css('-webkit-transform', computedStyle2.transform);
$('#div3').css('transform', computedStyle3.transform).css('-webkit-transform', computedStyle3.transform);
$('.spinner').addClass('paused');
});
</script>
</body>
&#13;
我不知道什么是React,但我认为代码必须是这样的(而不是$('#a').click(function ()....
块代码):
$('#a').on('click', () => {
var computedStyle1 = window.getComputedStyle(document.getElementById("div1"));
var computedStyle2 = window.getComputedStyle(document.getElementById("div2"));
var computedStyle3 = window.getComputedStyle(document.getElementById("div3"));
$('#div1').css('transform', computedStyle1.transform).css('-webkit-transform', computedStyle1.transform);
$('#div2').css('transform', computedStyle2.transform).css('-webkit-transform', computedStyle2.transform);
$('#div3').css('transform', computedStyle3.transform).css('-webkit-transform', computedStyle3.transform);
$('.spinner').addClass('paused');
});