我有五个按钮。如果单击按钮A,则它应处于活动状态,而其余按钮应被禁用。
现在,当多次单击任何一个禁用的字母按钮时,它会与激活的 一起被激活。
5个按钮中的每个按钮都有其自己的功能。当单击一个按钮时,相应的动画将连续开始。如果单击相同的A按钮,如何停止动画?如何禁用其他四个按钮?
var click = 0; //track the click
$('.particletext').click(function () {
if (click == 0) {
//for first click change the onclick function to stopAnimation() for the element which is clicked and remove onclick functions of others
$('.particletext').attr("onclick", "");
$(this).attr("onclick", "stopAnimation(this)");
click++;
} else { //for second click decrease the click to 0
click--;
}
})
function stopAnimation(element) {
$(element).children('span').remove(); //remove animating particles
//for second click re-add onclick functions to all elements
$('.hearts').each(function() {
$(this).attr("onclick", "hearts()");
$(this).attr("onclick");
})
$('.bubbles').each(function() {
$(this).attr("onclick", "bubbles()");
$(this).attr("onclick");
})
$('.sunbeams').each(function() {
$(this).attr("onclick", "sunbeams()");
})
$('.confetti').each(function() {
$(this).attr("onclick", "confetti()");
})
$('.fire').each(function() {
$(this).attr("onclick", "fire()");
})
}
function bubbles() {
$.each($(".particletext.bubbles"), function(){
var bubblecount = 4;
for(var i = 0; i <= bubblecount; i++) {
var size = ((Math.floor( Math.random() * (80 - 40 + 1) ) + 40)/10);
$(this).append('<span class="particle" style="top:' + 27 + '%; left:' + (Math.floor( Math.random() * (95 - 0 + 1) ) + 0) + '%;width:' + size + 'px; height:' + size + 'px;animation-delay: ' + 0.1 + 's;"></span>');
}
});
}
function hearts() {
$.each($(".particletext.hearts"), function(){
var heartcount = 3;
for(var i = 0; i <= heartcount; i++) {
var size = ((Math.floor( Math.random() * (120 - 60 + 1) ) + 60)/10);
$(this).append('<span class="particle" style="top:' + 11 + '%; left:' + (Math.floor( Math.random() * (95 - 0 + 1) ) + 0) + '%;width:' + size + 'px; height:' + size + 'px;animation-delay: ' + 0.1 + 's;"></span>');
}
});
}
function confetti() {
$.each($(".particletext.confetti"), function(){
var confetticount = 4;
for(var i = 0; i <= confetticount; i++) {
$(this).append('<span class="particle c' +(Math.floor( Math.random() * (2 - 1 + 1) ) + 1) + '" style="top:' + (Math.floor( Math.random() * (50 - 10 + 1) ) + 10) + '%; left:' + (Math.floor( Math.random() * (100 - 0 + 1) ) + 0) + '%;width:' + (Math.floor( Math.random() * (8 - 6 + 1) ) + 6)+ 'px; height:' + (Math.floor( Math.random() * (4 - 3+ 1) ) + 3) + 'px;animation-delay: ' + 0.1 + 's;"></span>');
}
});
}
function fire() {
$.each($(".particletext.fire"), function(){
var firecount = 2;
for(var i = 0; i <= firecount; i++) {
var size = Math.floor( Math.random() * (12 - 8 + 1) ) + 8;
$(this).append('<span class="particle" style="top:' + (Math.floor( Math.random() * (70 - 40 + 1) ) + 40) + '%; left:' + (Math.floor( Math.random() * (1 +20 + 11) ) + 1) + '%;width:' + size + 'px; height:' + size + 'px;animation-delay: ' + 0.1 + 's;"></span>');
}
});
}
function sunbeams() {
$.each($(".particletext.sunbeams"), function(){
var linecount = 3;
for(var i = 0; i <= linecount; i++) {
$(this).append('<span class="particle" style="top:' + (Math.floor( Math.random() * (0 + 40 + 1) ) - 40) + '%; left:' + (Math.floor( Math.random() * (100 - 0 + 1) ) + 0) + '%;width:' +(Math.floor( Math.random() * (2 - 1 + 1) ) + 1 )+ 'px; height:' + 35 + '%;animation-delay: -' + 0.1 + 's;"></span>');
}
});
}
.particletext {
text-align: center;
font-size: 48px;
position: relative;
}
.particletext.bubbles > .particle {
opacity: 0;
position: absolute;
background-color: rgba(33, 149, 243, 0.603);
-webkit-animation: bubbles 3s ease-in infinite;
animation: bubbles 3s ease-in infinite;
border-radius: 100%;
}
.particletext.hearts > .particle {
opacity: 0;
position: absolute;
background-color: rgba(204,42,93,1);
-webkit-animation: hearts 3s ease-in infinite;
animation: hearts 3s ease-in infinite;
}
.particletext.hearts > .particle:before,.particletext.hearts > .particle:after {
position: absolute;
content: '';
border-radius: 100px;
top: 0px;
left: 0px;
width: 100%;
height: 100%;
background-color: rgba(204,42,93,1);
}
.particletext.hearts > .particle:before {
-webkit-transform: translateX(-50%);
transform: translateX(-50%);
}
.particletext.hearts > .particle:after {
-webkit-transform: translateY(-50%);
transform: translateY(-50%);
}
.particletext.lines > .particle {
position: absolute;
background-color: rgba(244, 67, 54, 0.5);
-webkit-animation: lines 3s linear infinite;
animation: lines 3s linear infinite;
}
.particletext.confetti > .particle {
opacity: 0;
position: absolute;
-webkit-animation: confetti 3s ease-in infinite;
animation: confetti 3s ease-in infinite;
}
.particletext.confetti > .particle.c1 {
background-color: rgba(76, 175, 80, 0.5);
}
.particletext.confetti > .particle.c2 {
background-color: rgba(156, 39, 176, 0.5);
}
.particletext.fire > .particle {
position: absolute;
background-color: rgba(7, 141, 255, 0.5);
border-radius: 40px;
border-top-right-radius: 0px;
-webkit-animation: fires 0.8s linear infinite;
animation: fires 0.8s linear infinite;
-webkit-transform: rotate(-45deg);
transform: rotate(-45deg);
opacity: 0;
}
.particletext.fire > .particle:before {
position: absolute;
content: '';
top: 60%;
left: 40%;
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
width: 50%;
height: 50%;
border-radius: 40px;
border-top-right-radius: 0px;
background-color: rgba(0, 66, 251, 0.5);
}
.particletext.sunbeams > .particle {
position: absolute;
background-color:#dc3dd5;
border-radius: 100px;
top: 0px;
left: 0px;
width: 100%;
height: 100%;
-webkit-animation: sunbeams 3s linear infinite;
animation: sunbeams 3s linear infinite;
}
@-webkit-keyframes bubbles {
0% {
opacity: 0;
}
20% {
opacity: 1;
-webkit-transform: translate(0, -20%);
transform: translate(0, -20%);
}
100% {
opacity: 0;
-webkit-transform: translate(0, -1000%);
transform: translate(0, -1000%);
}
}
@keyframes bubbles {
0% {
opacity: 0;
}
20% {
opacity: 1;
-webkit-transform: translate(0, -20%);
transform: translate(0, -20%);
}
100% {
opacity: 0;
-webkit-transform: translate(0, -1000%);
transform: translate(0, -1000%);
}
}
@-webkit-keyframes hearts {
0% {
opacity: 0;
-webkit-transform: translate(0, 0%) rotate(45deg);
transform: translate(0, 0%) rotate(45deg);
}
20% {
opacity: 0.8;
-webkit-transform: translate(0, -20%) rotate(45deg);
transform: translate(0, -20%) rotate(45deg);
}
100% {
opacity: 0;
-webkit-transform: translate(0, -1000%) rotate(45deg);
transform: translate(0, -1000%) rotate(45deg);
}
}
@keyframes hearts {
0% {
opacity: 0;
-webkit-transform: translate(0, 0%) rotate(45deg);
transform: translate(0, 0%) rotate(45deg);
}
20% {
opacity: 0.8;
-webkit-transform: translate(0, -20%) rotate(45deg);
transform: translate(0, -20%) rotate(45deg);
}
100% {
opacity: 0;
-webkit-transform: translate(0, -1000%) rotate(45deg);
transform: translate(0, -1000%) rotate(45deg);
}
}
@-webkit-keyframes lines {
0%, 50%, 100% {
-webkit-transform: translateY(0%);
transform: translateY(0%);
}
25% {
-webkit-transform: translateY(100%);
transform: translateY(100%);
}
75% {
-webkit-transform: translateY(-100%);
transform: translateY(-100%);
}
}
@keyframes lines {
0%, 50%, 100% {
-webkit-transform: translateY(0%);
transform: translateY(0%);
}
25% {
-webkit-transform: translateY(100%);
transform: translateY(100%);
}
75% {
-webkit-transform: translateY(-100%);
transform: translateY(-100%);
}
}
@-webkit-keyframes confetti {
0% {
opacity: 0;
-webkit-transform: translateY(0%) rotate(0deg);
transform: translateY(0%) rotate(0deg);
}
10% {
opacity: 1;
}
35% {
-webkit-transform: translateY(-800%) rotate(270deg);
transform: translateY(-800%) rotate(270deg);
}
80% {
opacity: 1;
}
100% {
opacity: 0;
-webkit-transform: translateY(2000%) rotate(1440deg);
transform: translateY(2000%) rotate(1440deg);
}
}
@keyframes confetti {
0% {
opacity: 0;
-webkit-transform: translateY(0%) rotate(0deg);
transform: translateY(0%) rotate(0deg);
}
10% {
opacity: 1;
}
35% {
-webkit-transform: translateY(-800%) rotate(270deg);
transform: translateY(-800%) rotate(270deg);
}
80% {
opacity: 1;
}
100% {
opacity: 0;
-webkit-transform: translateY(2000%) rotate(1440deg);
transform: translateY(2000%) rotate(1440deg);
}
}
@-webkit-keyframes fires {
0% {
-webkit-transform: rotate(-70deg) translateY(0%);
transform: rotate(-70deg) translateY(0%);
}
25% {
-webkit-transform: rotate(-20deg) translateY(-5%);
transform: rotate(-20deg) translateY(-5%);
opacity: 1;
}
50% {
-webkit-transform: rotate(-70deg) translateY(-10%);
transform: rotate(-70deg) translateY(-10%);
}
75% {
-webkit-transform: rotate(-20deg) translateY(-20%);
transform: rotate(-20deg) translateY(-20%);
}
100% {
-webkit-transform: rotate(-70deg) translateY(-40%);
transform: rotate(-70deg) translateY(-40%);
opacity: 1;
}
}
@keyframes fires {
0% {
-webkit-transform: rotate(-70deg) translateY(0%);
transform: rotate(-70deg) translateY(0%);
}
25% {
-webkit-transform: rotate(-20deg) translateY(-5%);
transform: rotate(-20deg) translateY(-5%);
opacity: 1;
}
50% {
-webkit-transform: rotate(-70deg) translateY(-10%);
transform: rotate(-70deg) translateY(-10%);
}
75% {
-webkit-transform: rotate(-20deg) translateY(-20%);
transform: rotate(-20deg) translateY(-20%);
}
100% {
-webkit-transform: rotate(-70deg) translateY(-40%);
transform: rotate(-70deg) translateY(-40%);
opacity: 1;
}
}
@-webkit-keyframes sunbeams {
0% {
-webkit-transform: translateY(40%) rotate(0deg);
transform: translateY(40%) rotate(0deg);
}
50% {
-webkit-transform: translateY(-40%) rotate(180deg);
transform: translateY(-40%) rotate(180deg);
}
100% {
-webkit-transform: translateY(40%) rotate(360deg);
transform: translateY(40%) rotate(360deg);
}
0%,14%,17%,43%,53%,71%,80%,94%,100% {
opacity: 0;
}
6%,15%,24%,28%,48%,55%,78%,82%,99% {
opacity: 1;
}
}
@keyframes sunbeams {
0% {
-webkit-transform: translateY(40%) rotate(0deg);
transform: translateY(40%) rotate(0deg);
}
50% {
-webkit-transform: translateY(-40%) rotate(180deg);
transform: translateY(-40%) rotate(180deg);
}
100% {
-webkit-transform: translateY(40%) rotate(360deg);
transform: translateY(40%) rotate(360deg);
}
0%,14%,17%,43%,53%,71%,80%,94%,100% {
opacity: 0;
}
6%,15%,24%,28%,48%,55%,78%,82%,99% {
opacity: 1;
}
}
ul.socialIcons {
padding: 0;
text-align: center;
}
.socialIcons li {
background: #fff;
list-style: none;
display: inline-block;
margin: 0 25px;
font-size: 12px;
}
.socialIcons li a {
text-decoration: none;
color: #000;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<ul class="socialIcons">
<li class="particletext hearts" onclick="hearts()"><a>A</a></li>
<li class="particletext bubbles" onclick="bubbles()"><a>B</a></li>
<li class="particletext sunbeams" onclick="sunbeams()"><a>C</a></li>
<li class="particletext confetti" onclick="confetti()"><a>D</a></li>
<li class="particletext fire" onclick="fire()"><a>E</a></li>
</ul>
答案 0 :(得分:0)
使用ID进行操作比仅使用类更容易,因为当您查询类时,您会获得所有 all 类,因此有必要仅过滤出所需的类。因此,我添加了ID,以使工作更易于理解和编写。
您需要同时跟踪(a)动画是否当前处于活动状态和(b)哪个动画当前处于活动状态。
您只需要使用一种方法来处理事件:内联(例如onclick="fn_name"
-不推荐)或外部(在此示例中是这样做的方式)。您正在使用这两种方法,在这种情况下逻辑很容易混乱。
有一个巧妙的技巧可以根据存储在变量中的名称创建函数调用:
window[var_name]();
var active=false, active_anim='';
$('.particletext').click(function () {
if (!active) {
active = true;
active_anim = this.id;
window[active_anim]();
}else{
if (this.id == active_anim){
stopAnimation(active_anim);
active = false;
}else{
stopAnimation(active_anim);
active_anim = this.id;
window[active_anim]();
}
}
});
function stopAnimation(element) {
$('#'+element).children('span').remove(); //remove animating particles
}
function bubbles() {
$.each($(".particletext.bubbles"), function(){
var bubblecount = 4;
for(var i = 0; i <= bubblecount; i++) {
var size = ((Math.floor( Math.random() * (80 - 40 + 1) ) + 40)/10);
$(this).append('<span class="particle" style="top:' + 27 + '%; left:' + (Math.floor( Math.random() * (95 - 0 + 1) ) + 0) + '%;width:' + size + 'px; height:' + size + 'px;animation-delay: ' + 0.1 + 's;"></span>');
}
});
}
function hearts() {
$.each($(".particletext.hearts"), function(){
var heartcount = 3;
for(var i = 0; i <= heartcount; i++) {
var size = ((Math.floor( Math.random() * (120 - 60 + 1) ) + 60)/10);
$(this).append('<span class="particle" style="top:' + 11 + '%; left:' + (Math.floor( Math.random() * (95 - 0 + 1) ) + 0) + '%;width:' + size + 'px; height:' + size + 'px;animation-delay: ' + 0.1 + 's;"></span>');
}
});
}
function confetti() {
$.each($(".particletext.confetti"), function(){
var confetticount = 4;
for(var i = 0; i <= confetticount; i++) {
$(this).append('<span class="particle c' +(Math.floor( Math.random() * (2 - 1 + 1) ) + 1) + '" style="top:' + (Math.floor( Math.random() * (50 - 10 + 1) ) + 10) + '%; left:' + (Math.floor( Math.random() * (100 - 0 + 1) ) + 0) + '%;width:' + (Math.floor( Math.random() * (8 - 6 + 1) ) + 6)+ 'px; height:' + (Math.floor( Math.random() * (4 - 3+ 1) ) + 3) + 'px;animation-delay: ' + 0.1 + 's;"></span>');
}
});
}
function fire() {
$.each($(".particletext.fire"), function(){
var firecount = 2;
for(var i = 0; i <= firecount; i++) {
var size = Math.floor( Math.random() * (12 - 8 + 1) ) + 8;
$(this).append('<span class="particle" style="top:' + (Math.floor( Math.random() * (70 - 40 + 1) ) + 40) + '%; left:' + (Math.floor( Math.random() * (1 +20 + 11) ) + 1) + '%;width:' + size + 'px; height:' + size + 'px;animation-delay: ' + 0.1 + 's;"></span>');
}
});
}
function sunbeams() {
$.each($(".particletext.sunbeams"), function(){
var linecount = 3;
for(var i = 0; i <= linecount; i++) {
$(this).append('<span class="particle" style="top:' + (Math.floor( Math.random() * (0 + 40 + 1) ) - 40) + '%; left:' + (Math.floor( Math.random() * (100 - 0 + 1) ) + 0) + '%;width:' +(Math.floor( Math.random() * (2 - 1 + 1) ) + 1 )+ 'px; height:' + 35 + '%;animation-delay: -' + 0.1 + 's;"></span>');
}
});
}
.particletext {
text-align: center;
font-size: 48px;
position: relative;
}
.particletext.bubbles > .particle {
opacity: 0;
position: absolute;
background-color: rgba(33, 149, 243, 0.603);
-webkit-animation: bubbles 3s ease-in infinite;
animation: bubbles 3s ease-in infinite;
border-radius: 100%;
}
.particletext.hearts > .particle {
opacity: 0;
position: absolute;
background-color: rgba(204,42,93,1);
-webkit-animation: hearts 3s ease-in infinite;
animation: hearts 3s ease-in infinite;
}
.particletext.hearts > .particle:before,.particletext.hearts > .particle:after {
position: absolute;
content: '';
border-radius: 100px;
top: 0px;
left: 0px;
width: 100%;
height: 100%;
background-color: rgba(204,42,93,1);
}
.particletext.hearts > .particle:before {
-webkit-transform: translateX(-50%);
transform: translateX(-50%);
}
.particletext.hearts > .particle:after {
-webkit-transform: translateY(-50%);
transform: translateY(-50%);
}
.particletext.lines > .particle {
position: absolute;
background-color: rgba(244, 67, 54, 0.5);
-webkit-animation: lines 3s linear infinite;
animation: lines 3s linear infinite;
}
.particletext.confetti > .particle {
opacity: 0;
position: absolute;
-webkit-animation: confetti 3s ease-in infinite;
animation: confetti 3s ease-in infinite;
}
.particletext.confetti > .particle.c1 {
background-color: rgba(76, 175, 80, 0.5);
}
.particletext.confetti > .particle.c2 {
background-color: rgba(156, 39, 176, 0.5);
}
.particletext.fire > .particle {
position: absolute;
background-color: rgba(7, 141, 255, 0.5);
border-radius: 40px;
border-top-right-radius: 0px;
-webkit-animation: fires 0.8s linear infinite;
animation: fires 0.8s linear infinite;
-webkit-transform: rotate(-45deg);
transform: rotate(-45deg);
opacity: 0;
}
.particletext.fire > .particle:before {
position: absolute;
content: '';
top: 60%;
left: 40%;
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
width: 50%;
height: 50%;
border-radius: 40px;
border-top-right-radius: 0px;
background-color: rgba(0, 66, 251, 0.5);
}
.particletext.sunbeams > .particle {
position: absolute;
background-color:#dc3dd5;
border-radius: 100px;
top: 0px;
left: 0px;
width: 100%;
height: 100%;
-webkit-animation: sunbeams 3s linear infinite;
animation: sunbeams 3s linear infinite;
}
@-webkit-keyframes bubbles {
0% {
opacity: 0;
}
20% {
opacity: 1;
-webkit-transform: translate(0, -20%);
transform: translate(0, -20%);
}
100% {
opacity: 0;
-webkit-transform: translate(0, -1000%);
transform: translate(0, -1000%);
}
}
@keyframes bubbles {
0% {
opacity: 0;
}
20% {
opacity: 1;
-webkit-transform: translate(0, -20%);
transform: translate(0, -20%);
}
100% {
opacity: 0;
-webkit-transform: translate(0, -1000%);
transform: translate(0, -1000%);
}
}
@-webkit-keyframes hearts {
0% {
opacity: 0;
-webkit-transform: translate(0, 0%) rotate(45deg);
transform: translate(0, 0%) rotate(45deg);
}
20% {
opacity: 0.8;
-webkit-transform: translate(0, -20%) rotate(45deg);
transform: translate(0, -20%) rotate(45deg);
}
100% {
opacity: 0;
-webkit-transform: translate(0, -1000%) rotate(45deg);
transform: translate(0, -1000%) rotate(45deg);
}
}
@keyframes hearts {
0% {
opacity: 0;
-webkit-transform: translate(0, 0%) rotate(45deg);
transform: translate(0, 0%) rotate(45deg);
}
20% {
opacity: 0.8;
-webkit-transform: translate(0, -20%) rotate(45deg);
transform: translate(0, -20%) rotate(45deg);
}
100% {
opacity: 0;
-webkit-transform: translate(0, -1000%) rotate(45deg);
transform: translate(0, -1000%) rotate(45deg);
}
}
@-webkit-keyframes lines {
0%, 50%, 100% {
-webkit-transform: translateY(0%);
transform: translateY(0%);
}
25% {
-webkit-transform: translateY(100%);
transform: translateY(100%);
}
75% {
-webkit-transform: translateY(-100%);
transform: translateY(-100%);
}
}
@keyframes lines {
0%, 50%, 100% {
-webkit-transform: translateY(0%);
transform: translateY(0%);
}
25% {
-webkit-transform: translateY(100%);
transform: translateY(100%);
}
75% {
-webkit-transform: translateY(-100%);
transform: translateY(-100%);
}
}
@-webkit-keyframes confetti {
0% {
opacity: 0;
-webkit-transform: translateY(0%) rotate(0deg);
transform: translateY(0%) rotate(0deg);
}
10% {
opacity: 1;
}
35% {
-webkit-transform: translateY(-800%) rotate(270deg);
transform: translateY(-800%) rotate(270deg);
}
80% {
opacity: 1;
}
100% {
opacity: 0;
-webkit-transform: translateY(2000%) rotate(1440deg);
transform: translateY(2000%) rotate(1440deg);
}
}
@keyframes confetti {
0% {
opacity: 0;
-webkit-transform: translateY(0%) rotate(0deg);
transform: translateY(0%) rotate(0deg);
}
10% {
opacity: 1;
}
35% {
-webkit-transform: translateY(-800%) rotate(270deg);
transform: translateY(-800%) rotate(270deg);
}
80% {
opacity: 1;
}
100% {
opacity: 0;
-webkit-transform: translateY(2000%) rotate(1440deg);
transform: translateY(2000%) rotate(1440deg);
}
}
@-webkit-keyframes fires {
0% {
-webkit-transform: rotate(-70deg) translateY(0%);
transform: rotate(-70deg) translateY(0%);
}
25% {
-webkit-transform: rotate(-20deg) translateY(-5%);
transform: rotate(-20deg) translateY(-5%);
opacity: 1;
}
50% {
-webkit-transform: rotate(-70deg) translateY(-10%);
transform: rotate(-70deg) translateY(-10%);
}
75% {
-webkit-transform: rotate(-20deg) translateY(-20%);
transform: rotate(-20deg) translateY(-20%);
}
100% {
-webkit-transform: rotate(-70deg) translateY(-40%);
transform: rotate(-70deg) translateY(-40%);
opacity: 1;
}
}
@keyframes fires {
0% {
-webkit-transform: rotate(-70deg) translateY(0%);
transform: rotate(-70deg) translateY(0%);
}
25% {
-webkit-transform: rotate(-20deg) translateY(-5%);
transform: rotate(-20deg) translateY(-5%);
opacity: 1;
}
50% {
-webkit-transform: rotate(-70deg) translateY(-10%);
transform: rotate(-70deg) translateY(-10%);
}
75% {
-webkit-transform: rotate(-20deg) translateY(-20%);
transform: rotate(-20deg) translateY(-20%);
}
100% {
-webkit-transform: rotate(-70deg) translateY(-40%);
transform: rotate(-70deg) translateY(-40%);
opacity: 1;
}
}
@-webkit-keyframes sunbeams {
0% {
-webkit-transform: translateY(40%) rotate(0deg);
transform: translateY(40%) rotate(0deg);
}
50% {
-webkit-transform: translateY(-40%) rotate(180deg);
transform: translateY(-40%) rotate(180deg);
}
100% {
-webkit-transform: translateY(40%) rotate(360deg);
transform: translateY(40%) rotate(360deg);
}
0%,14%,17%,43%,53%,71%,80%,94%,100% {
opacity: 0;
}
6%,15%,24%,28%,48%,55%,78%,82%,99% {
opacity: 1;
}
}
@keyframes sunbeams {
0% {
-webkit-transform: translateY(40%) rotate(0deg);
transform: translateY(40%) rotate(0deg);
}
50% {
-webkit-transform: translateY(-40%) rotate(180deg);
transform: translateY(-40%) rotate(180deg);
}
100% {
-webkit-transform: translateY(40%) rotate(360deg);
transform: translateY(40%) rotate(360deg);
}
0%,14%,17%,43%,53%,71%,80%,94%,100% {
opacity: 0;
}
6%,15%,24%,28%,48%,55%,78%,82%,99% {
opacity: 1;
}
}
ul.socialIcons {
padding: 0;
text-align: center;
}
.socialIcons li {
background: #fff;
list-style: none;
display: inline-block;
margin: 0 25px;
font-size: 12px;
}
.socialIcons li a {
text-decoration: none;
color: #000;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<ul class="socialIcons">
<li id="hearts" class="particletext hearts"><a>A</a></li>
<li id="bubbles" class="particletext bubbles"><a>B</a></li>
<li id="sunbeams" class="particletext sunbeams"><a>C</a></li>
<li id="confetti" class="particletext confetti"><a>D</a></li>
<li id="fire" class="particletext fire"><a>E</a></li>
</ul>
我误解了您的问题,并创建了一个示例,其中单击按钮A开始动画,然后单击另一个按钮停止第一个动画并开始新的动画。
那可能不是您想要的。重新阅读您的问题,似乎您要在当前正在运行动画的同时禁用其他按钮,而只允许用户再次单击同一按钮以停止该动画。
如果是这样,这是为您提供的修订示例:
var active=false, active_anim='';
$('.particletext').click(function () {
if (!active) {
active = true;
active_anim = this.id;
$(this).addClass('activebox'); //<=== also added
window[active_anim]();
}else{
if (this.id == active_anim){
$('.particletext').removeClass('activebox'); //<=== also added
stopAnimation(active_anim);
active = false;
}else{
console.log('Button ' +this.id+ ' ignored')
}
}
});
function stopAnimation(element) {
$('#'+element).children('span').remove(); //remove animating particles
}
function bubbles() {
$.each($(".particletext.bubbles"), function(){
var bubblecount = 4;
for(var i = 0; i <= bubblecount; i++) {
var size = ((Math.floor( Math.random() * (80 - 40 + 1) ) + 40)/10);
$(this).append('<span class="particle" style="top:' + 27 + '%; left:' + (Math.floor( Math.random() * (95 - 0 + 1) ) + 0) + '%;width:' + size + 'px; height:' + size + 'px;animation-delay: ' + 0.1 + 's;"></span>');
}
});
}
function hearts() {
$.each($(".particletext.hearts"), function(){
var heartcount = 3;
for(var i = 0; i <= heartcount; i++) {
var size = ((Math.floor( Math.random() * (120 - 60 + 1) ) + 60)/10);
$(this).append('<span class="particle" style="top:' + 11 + '%; left:' + (Math.floor( Math.random() * (95 - 0 + 1) ) + 0) + '%;width:' + size + 'px; height:' + size + 'px;animation-delay: ' + 0.1 + 's;"></span>');
}
});
}
function confetti() {
$.each($(".particletext.confetti"), function(){
var confetticount = 4;
for(var i = 0; i <= confetticount; i++) {
$(this).append('<span class="particle c' +(Math.floor( Math.random() * (2 - 1 + 1) ) + 1) + '" style="top:' + (Math.floor( Math.random() * (50 - 10 + 1) ) + 10) + '%; left:' + (Math.floor( Math.random() * (100 - 0 + 1) ) + 0) + '%;width:' + (Math.floor( Math.random() * (8 - 6 + 1) ) + 6)+ 'px; height:' + (Math.floor( Math.random() * (4 - 3+ 1) ) + 3) + 'px;animation-delay: ' + 0.1 + 's;"></span>');
}
});
}
function fire() {
$.each($(".particletext.fire"), function(){
var firecount = 2;
for(var i = 0; i <= firecount; i++) {
var size = Math.floor( Math.random() * (12 - 8 + 1) ) + 8;
$(this).append('<span class="particle" style="top:' + (Math.floor( Math.random() * (70 - 40 + 1) ) + 40) + '%; left:' + (Math.floor( Math.random() * (1 +20 + 11) ) + 1) + '%;width:' + size + 'px; height:' + size + 'px;animation-delay: ' + 0.1 + 's;"></span>');
}
});
}
function sunbeams() {
$.each($(".particletext.sunbeams"), function(){
var linecount = 3;
for(var i = 0; i <= linecount; i++) {
$(this).append('<span class="particle" style="top:' + (Math.floor( Math.random() * (0 + 40 + 1) ) - 40) + '%; left:' + (Math.floor( Math.random() * (100 - 0 + 1) ) + 0) + '%;width:' +(Math.floor( Math.random() * (2 - 1 + 1) ) + 1 )+ 'px; height:' + 35 + '%;animation-delay: -' + 0.1 + 's;"></span>');
}
});
}
.particletext{border:1px solid transparent;padding:2px;}
.activebox{border:1px solid green;}
.particletext {
text-align: center;
font-size: 48px;
position: relative;
}
.particletext.bubbles > .particle {
opacity: 0;
position: absolute;
background-color: rgba(33, 149, 243, 0.603);
-webkit-animation: bubbles 3s ease-in infinite;
animation: bubbles 3s ease-in infinite;
border-radius: 100%;
}
.particletext.hearts > .particle {
opacity: 0;
position: absolute;
background-color: rgba(204,42,93,1);
-webkit-animation: hearts 3s ease-in infinite;
animation: hearts 3s ease-in infinite;
}
.particletext.hearts > .particle:before,.particletext.hearts > .particle:after {
position: absolute;
content: '';
border-radius: 100px;
top: 0px;
left: 0px;
width: 100%;
height: 100%;
background-color: rgba(204,42,93,1);
}
.particletext.hearts > .particle:before {
-webkit-transform: translateX(-50%);
transform: translateX(-50%);
}
.particletext.hearts > .particle:after {
-webkit-transform: translateY(-50%);
transform: translateY(-50%);
}
.particletext.lines > .particle {
position: absolute;
background-color: rgba(244, 67, 54, 0.5);
-webkit-animation: lines 3s linear infinite;
animation: lines 3s linear infinite;
}
.particletext.confetti > .particle {
opacity: 0;
position: absolute;
-webkit-animation: confetti 3s ease-in infinite;
animation: confetti 3s ease-in infinite;
}
.particletext.confetti > .particle.c1 {
background-color: rgba(76, 175, 80, 0.5);
}
.particletext.confetti > .particle.c2 {
background-color: rgba(156, 39, 176, 0.5);
}
.particletext.fire > .particle {
position: absolute;
background-color: rgba(7, 141, 255, 0.5);
border-radius: 40px;
border-top-right-radius: 0px;
-webkit-animation: fires 0.8s linear infinite;
animation: fires 0.8s linear infinite;
-webkit-transform: rotate(-45deg);
transform: rotate(-45deg);
opacity: 0;
}
.particletext.fire > .particle:before {
position: absolute;
content: '';
top: 60%;
left: 40%;
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
width: 50%;
height: 50%;
border-radius: 40px;
border-top-right-radius: 0px;
background-color: rgba(0, 66, 251, 0.5);
}
.particletext.sunbeams > .particle {
position: absolute;
background-color:#dc3dd5;
border-radius: 100px;
top: 0px;
left: 0px;
width: 100%;
height: 100%;
-webkit-animation: sunbeams 3s linear infinite;
animation: sunbeams 3s linear infinite;
}
@-webkit-keyframes bubbles {
0% {
opacity: 0;
}
20% {
opacity: 1;
-webkit-transform: translate(0, -20%);
transform: translate(0, -20%);
}
100% {
opacity: 0;
-webkit-transform: translate(0, -1000%);
transform: translate(0, -1000%);
}
}
@keyframes bubbles {
0% {
opacity: 0;
}
20% {
opacity: 1;
-webkit-transform: translate(0, -20%);
transform: translate(0, -20%);
}
100% {
opacity: 0;
-webkit-transform: translate(0, -1000%);
transform: translate(0, -1000%);
}
}
@-webkit-keyframes hearts {
0% {
opacity: 0;
-webkit-transform: translate(0, 0%) rotate(45deg);
transform: translate(0, 0%) rotate(45deg);
}
20% {
opacity: 0.8;
-webkit-transform: translate(0, -20%) rotate(45deg);
transform: translate(0, -20%) rotate(45deg);
}
100% {
opacity: 0;
-webkit-transform: translate(0, -1000%) rotate(45deg);
transform: translate(0, -1000%) rotate(45deg);
}
}
@keyframes hearts {
0% {
opacity: 0;
-webkit-transform: translate(0, 0%) rotate(45deg);
transform: translate(0, 0%) rotate(45deg);
}
20% {
opacity: 0.8;
-webkit-transform: translate(0, -20%) rotate(45deg);
transform: translate(0, -20%) rotate(45deg);
}
100% {
opacity: 0;
-webkit-transform: translate(0, -1000%) rotate(45deg);
transform: translate(0, -1000%) rotate(45deg);
}
}
@-webkit-keyframes lines {
0%, 50%, 100% {
-webkit-transform: translateY(0%);
transform: translateY(0%);
}
25% {
-webkit-transform: translateY(100%);
transform: translateY(100%);
}
75% {
-webkit-transform: translateY(-100%);
transform: translateY(-100%);
}
}
@keyframes lines {
0%, 50%, 100% {
-webkit-transform: translateY(0%);
transform: translateY(0%);
}
25% {
-webkit-transform: translateY(100%);
transform: translateY(100%);
}
75% {
-webkit-transform: translateY(-100%);
transform: translateY(-100%);
}
}
@-webkit-keyframes confetti {
0% {
opacity: 0;
-webkit-transform: translateY(0%) rotate(0deg);
transform: translateY(0%) rotate(0deg);
}
10% {
opacity: 1;
}
35% {
-webkit-transform: translateY(-800%) rotate(270deg);
transform: translateY(-800%) rotate(270deg);
}
80% {
opacity: 1;
}
100% {
opacity: 0;
-webkit-transform: translateY(2000%) rotate(1440deg);
transform: translateY(2000%) rotate(1440deg);
}
}
@keyframes confetti {
0% {
opacity: 0;
-webkit-transform: translateY(0%) rotate(0deg);
transform: translateY(0%) rotate(0deg);
}
10% {
opacity: 1;
}
35% {
-webkit-transform: translateY(-800%) rotate(270deg);
transform: translateY(-800%) rotate(270deg);
}
80% {
opacity: 1;
}
100% {
opacity: 0;
-webkit-transform: translateY(2000%) rotate(1440deg);
transform: translateY(2000%) rotate(1440deg);
}
}
@-webkit-keyframes fires {
0% {
-webkit-transform: rotate(-70deg) translateY(0%);
transform: rotate(-70deg) translateY(0%);
}
25% {
-webkit-transform: rotate(-20deg) translateY(-5%);
transform: rotate(-20deg) translateY(-5%);
opacity: 1;
}
50% {
-webkit-transform: rotate(-70deg) translateY(-10%);
transform: rotate(-70deg) translateY(-10%);
}
75% {
-webkit-transform: rotate(-20deg) translateY(-20%);
transform: rotate(-20deg) translateY(-20%);
}
100% {
-webkit-transform: rotate(-70deg) translateY(-40%);
transform: rotate(-70deg) translateY(-40%);
opacity: 1;
}
}
@keyframes fires {
0% {
-webkit-transform: rotate(-70deg) translateY(0%);
transform: rotate(-70deg) translateY(0%);
}
25% {
-webkit-transform: rotate(-20deg) translateY(-5%);
transform: rotate(-20deg) translateY(-5%);
opacity: 1;
}
50% {
-webkit-transform: rotate(-70deg) translateY(-10%);
transform: rotate(-70deg) translateY(-10%);
}
75% {
-webkit-transform: rotate(-20deg) translateY(-20%);
transform: rotate(-20deg) translateY(-20%);
}
100% {
-webkit-transform: rotate(-70deg) translateY(-40%);
transform: rotate(-70deg) translateY(-40%);
opacity: 1;
}
}
@-webkit-keyframes sunbeams {
0% {
-webkit-transform: translateY(40%) rotate(0deg);
transform: translateY(40%) rotate(0deg);
}
50% {
-webkit-transform: translateY(-40%) rotate(180deg);
transform: translateY(-40%) rotate(180deg);
}
100% {
-webkit-transform: translateY(40%) rotate(360deg);
transform: translateY(40%) rotate(360deg);
}
0%,14%,17%,43%,53%,71%,80%,94%,100% {
opacity: 0;
}
6%,15%,24%,28%,48%,55%,78%,82%,99% {
opacity: 1;
}
}
@keyframes sunbeams {
0% {
-webkit-transform: translateY(40%) rotate(0deg);
transform: translateY(40%) rotate(0deg);
}
50% {
-webkit-transform: translateY(-40%) rotate(180deg);
transform: translateY(-40%) rotate(180deg);
}
100% {
-webkit-transform: translateY(40%) rotate(360deg);
transform: translateY(40%) rotate(360deg);
}
0%,14%,17%,43%,53%,71%,80%,94%,100% {
opacity: 0;
}
6%,15%,24%,28%,48%,55%,78%,82%,99% {
opacity: 1;
}
}
ul.socialIcons {
padding: 0;
text-align: center;
}
.socialIcons li {
background: #fff;
list-style: none;
display: inline-block;
margin: 0 25px;
font-size: 12px;
}
.socialIcons li a {
text-decoration: none;
color: #000;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<ul class="socialIcons">
<li id="hearts" class="particletext hearts"><a>A</a></li>
<li id="bubbles" class="particletext bubbles"><a>B</a></li>
<li id="sunbeams" class="particletext sunbeams"><a>C</a></li>
<li id="confetti" class="particletext confetti"><a>D</a></li>
<li id="fire" class="particletext fire"><a>E</a></li>
</ul>
答案 1 :(得分:0)
这是解决方案。 js文件中的一些更改,并且我已使用注释将更改分开。
//my code starts here
var click = 0; //track the click
var elementClassName;
$('.particletext').click(function () {
if (click == 0) {
elementClassName = $(this).attr('class');
//for first click change the onclick function to stopAnimation() for the element which is clicked and remove onclick functions of others
$('.particletext').attr("onclick", "");
$(this).attr("onclick", "stopAnimation(this)");
click++;
} else { //for second click decrease the click to 0
if ($(this).attr('class') == elementClassName) {
click--;
}
}
})
//my code ends here
function stopAnimation(element) {
$(element).children('span').remove(); //remove animating particles
//for second click re-add onclick functions to all elements
$('.hearts').each(function() {
$(this).attr("onclick", "hearts()");
$(this).attr("onclick");
})
$('.bubbles').each(function() {
$(this).attr("onclick", "bubbles()");
$(this).attr("onclick");
})
$('.sunbeams').each(function() {
$(this).attr("onclick", "sunbeams()");
})
$('.confetti').each(function() {
$(this).attr("onclick", "confetti()");
})
$('.fire').each(function() {
$(this).attr("onclick", "fire()");
})
}
function bubbles() {
$.each($(".particletext.bubbles"), function(){
var bubblecount = 4;
for(var i = 0; i <= bubblecount; i++) {
var size = ((Math.floor( Math.random() * (80 - 40 + 1) ) + 40)/10);
$(this).append('<span class="particle" style="top:' + 27 + '%; left:' + (Math.floor( Math.random() * (95 - 0 + 1) ) + 0) + '%;width:' + size + 'px; height:' + size + 'px;animation-delay: ' + 0.1 + 's;"></span>');
}
});
}
function hearts() {
$.each($(".particletext.hearts"), function(){
var heartcount = 3;
for(var i = 0; i <= heartcount; i++) {
var size = ((Math.floor( Math.random() * (120 - 60 + 1) ) + 60)/10);
$(this).append('<span class="particle" style="top:' + 11 + '%; left:' + (Math.floor( Math.random() * (95 - 0 + 1) ) + 0) + '%;width:' + size + 'px; height:' + size + 'px;animation-delay: ' + 0.1 + 's;"></span>');
}
});
}
function confetti() {
$.each($(".particletext.confetti"), function(){
var confetticount = 4;
for(var i = 0; i <= confetticount; i++) {
$(this).append('<span class="particle c' +(Math.floor( Math.random() * (2 - 1 + 1) ) + 1) + '" style="top:' + (Math.floor( Math.random() * (50 - 10 + 1) ) + 10) + '%; left:' + (Math.floor( Math.random() * (100 - 0 + 1) ) + 0) + '%;width:' + (Math.floor( Math.random() * (8 - 6 + 1) ) + 6)+ 'px; height:' + (Math.floor( Math.random() * (4 - 3+ 1) ) + 3) + 'px;animation-delay: ' + 0.1 + 's;"></span>');
}
});
}
function fire() {
$.each($(".particletext.fire"), function(){
var firecount = 2;
for(var i = 0; i <= firecount; i++) {
var size = Math.floor( Math.random() * (12 - 8 + 1) ) + 8;
$(this).append('<span class="particle" style="top:' + (Math.floor( Math.random() * (70 - 40 + 1) ) + 40) + '%; left:' + (Math.floor( Math.random() * (1 +20 + 11) ) + 1) + '%;width:' + size + 'px; height:' + size + 'px;animation-delay: ' + 0.1 + 's;"></span>');
}
});
}
function sunbeams() {
$.each($(".particletext.sunbeams"), function(){
var linecount = 3;
for(var i = 0; i <= linecount; i++) {
$(this).append('<span class="particle" style="top:' + (Math.floor( Math.random() * (0 + 40 + 1) ) - 40) + '%; left:' + (Math.floor( Math.random() * (100 - 0 + 1) ) + 0) + '%;width:' +(Math.floor( Math.random() * (2 - 1 + 1) ) + 1 )+ 'px; height:' + 35 + '%;animation-delay: -' + 0.1 + 's;"></span>');
}
});
}
.particletext {
text-align: center;
font-size: 48px;
position: relative;
}
.particletext.bubbles > .particle {
opacity: 0;
position: absolute;
background-color: rgba(33, 149, 243, 0.603);
-webkit-animation: bubbles 3s ease-in infinite;
animation: bubbles 3s ease-in infinite;
border-radius: 100%;
}
.particletext.hearts > .particle {
opacity: 0;
position: absolute;
background-color: rgba(204,42,93,1);
-webkit-animation: hearts 3s ease-in infinite;
animation: hearts 3s ease-in infinite;
}
.particletext.hearts > .particle:before,.particletext.hearts > .particle:after {
position: absolute;
content: '';
border-radius: 100px;
top: 0px;
left: 0px;
width: 100%;
height: 100%;
background-color: rgba(204,42,93,1);
}
.particletext.hearts > .particle:before {
-webkit-transform: translateX(-50%);
transform: translateX(-50%);
}
.particletext.hearts > .particle:after {
-webkit-transform: translateY(-50%);
transform: translateY(-50%);
}
.particletext.lines > .particle {
position: absolute;
background-color: rgba(244, 67, 54, 0.5);
-webkit-animation: lines 3s linear infinite;
animation: lines 3s linear infinite;
}
.particletext.confetti > .particle {
opacity: 0;
position: absolute;
-webkit-animation: confetti 3s ease-in infinite;
animation: confetti 3s ease-in infinite;
}
.particletext.confetti > .particle.c1 {
background-color: rgba(76, 175, 80, 0.5);
}
.particletext.confetti > .particle.c2 {
background-color: rgba(156, 39, 176, 0.5);
}
.particletext.fire > .particle {
position: absolute;
background-color: rgba(7, 141, 255, 0.5);
border-radius: 40px;
border-top-right-radius: 0px;
-webkit-animation: fires 0.8s linear infinite;
animation: fires 0.8s linear infinite;
-webkit-transform: rotate(-45deg);
transform: rotate(-45deg);
opacity: 0;
}
.particletext.fire > .particle:before {
position: absolute;
content: '';
top: 60%;
left: 40%;
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
width: 50%;
height: 50%;
border-radius: 40px;
border-top-right-radius: 0px;
background-color: rgba(0, 66, 251, 0.5);
}
.particletext.sunbeams > .particle {
position: absolute;
background-color:#dc3dd5;
border-radius: 100px;
top: 0px;
left: 0px;
width: 100%;
height: 100%;
-webkit-animation: sunbeams 3s linear infinite;
animation: sunbeams 3s linear infinite;
}
@-webkit-keyframes bubbles {
0% {
opacity: 0;
}
20% {
opacity: 1;
-webkit-transform: translate(0, -20%);
transform: translate(0, -20%);
}
100% {
opacity: 0;
-webkit-transform: translate(0, -1000%);
transform: translate(0, -1000%);
}
}
@keyframes bubbles {
0% {
opacity: 0;
}
20% {
opacity: 1;
-webkit-transform: translate(0, -20%);
transform: translate(0, -20%);
}
100% {
opacity: 0;
-webkit-transform: translate(0, -1000%);
transform: translate(0, -1000%);
}
}
@-webkit-keyframes hearts {
0% {
opacity: 0;
-webkit-transform: translate(0, 0%) rotate(45deg);
transform: translate(0, 0%) rotate(45deg);
}
20% {
opacity: 0.8;
-webkit-transform: translate(0, -20%) rotate(45deg);
transform: translate(0, -20%) rotate(45deg);
}
100% {
opacity: 0;
-webkit-transform: translate(0, -1000%) rotate(45deg);
transform: translate(0, -1000%) rotate(45deg);
}
}
@keyframes hearts {
0% {
opacity: 0;
-webkit-transform: translate(0, 0%) rotate(45deg);
transform: translate(0, 0%) rotate(45deg);
}
20% {
opacity: 0.8;
-webkit-transform: translate(0, -20%) rotate(45deg);
transform: translate(0, -20%) rotate(45deg);
}
100% {
opacity: 0;
-webkit-transform: translate(0, -1000%) rotate(45deg);
transform: translate(0, -1000%) rotate(45deg);
}
}
@-webkit-keyframes lines {
0%, 50%, 100% {
-webkit-transform: translateY(0%);
transform: translateY(0%);
}
25% {
-webkit-transform: translateY(100%);
transform: translateY(100%);
}
75% {
-webkit-transform: translateY(-100%);
transform: translateY(-100%);
}
}
@keyframes lines {
0%, 50%, 100% {
-webkit-transform: translateY(0%);
transform: translateY(0%);
}
25% {
-webkit-transform: translateY(100%);
transform: translateY(100%);
}
75% {
-webkit-transform: translateY(-100%);
transform: translateY(-100%);
}
}
@-webkit-keyframes confetti {
0% {
opacity: 0;
-webkit-transform: translateY(0%) rotate(0deg);
transform: translateY(0%) rotate(0deg);
}
10% {
opacity: 1;
}
35% {
-webkit-transform: translateY(-800%) rotate(270deg);
transform: translateY(-800%) rotate(270deg);
}
80% {
opacity: 1;
}
100% {
opacity: 0;
-webkit-transform: translateY(2000%) rotate(1440deg);
transform: translateY(2000%) rotate(1440deg);
}
}
@keyframes confetti {
0% {
opacity: 0;
-webkit-transform: translateY(0%) rotate(0deg);
transform: translateY(0%) rotate(0deg);
}
10% {
opacity: 1;
}
35% {
-webkit-transform: translateY(-800%) rotate(270deg);
transform: translateY(-800%) rotate(270deg);
}
80% {
opacity: 1;
}
100% {
opacity: 0;
-webkit-transform: translateY(2000%) rotate(1440deg);
transform: translateY(2000%) rotate(1440deg);
}
}
@-webkit-keyframes fires {
0% {
-webkit-transform: rotate(-70deg) translateY(0%);
transform: rotate(-70deg) translateY(0%);
}
25% {
-webkit-transform: rotate(-20deg) translateY(-5%);
transform: rotate(-20deg) translateY(-5%);
opacity: 1;
}
50% {
-webkit-transform: rotate(-70deg) translateY(-10%);
transform: rotate(-70deg) translateY(-10%);
}
75% {
-webkit-transform: rotate(-20deg) translateY(-20%);
transform: rotate(-20deg) translateY(-20%);
}
100% {
-webkit-transform: rotate(-70deg) translateY(-40%);
transform: rotate(-70deg) translateY(-40%);
opacity: 1;
}
}
@keyframes fires {
0% {
-webkit-transform: rotate(-70deg) translateY(0%);
transform: rotate(-70deg) translateY(0%);
}
25% {
-webkit-transform: rotate(-20deg) translateY(-5%);
transform: rotate(-20deg) translateY(-5%);
opacity: 1;
}
50% {
-webkit-transform: rotate(-70deg) translateY(-10%);
transform: rotate(-70deg) translateY(-10%);
}
75% {
-webkit-transform: rotate(-20deg) translateY(-20%);
transform: rotate(-20deg) translateY(-20%);
}
100% {
-webkit-transform: rotate(-70deg) translateY(-40%);
transform: rotate(-70deg) translateY(-40%);
opacity: 1;
}
}
@-webkit-keyframes sunbeams {
0% {
-webkit-transform: translateY(40%) rotate(0deg);
transform: translateY(40%) rotate(0deg);
}
50% {
-webkit-transform: translateY(-40%) rotate(180deg);
transform: translateY(-40%) rotate(180deg);
}
100% {
-webkit-transform: translateY(40%) rotate(360deg);
transform: translateY(40%) rotate(360deg);
}
0%,14%,17%,43%,53%,71%,80%,94%,100% {
opacity: 0;
}
6%,15%,24%,28%,48%,55%,78%,82%,99% {
opacity: 1;
}
}
@keyframes sunbeams {
0% {
-webkit-transform: translateY(40%) rotate(0deg);
transform: translateY(40%) rotate(0deg);
}
50% {
-webkit-transform: translateY(-40%) rotate(180deg);
transform: translateY(-40%) rotate(180deg);
}
100% {
-webkit-transform: translateY(40%) rotate(360deg);
transform: translateY(40%) rotate(360deg);
}
0%,14%,17%,43%,53%,71%,80%,94%,100% {
opacity: 0;
}
6%,15%,24%,28%,48%,55%,78%,82%,99% {
opacity: 1;
}
}
ul.socialIcons {
padding: 0;
text-align: center;
}
.socialIcons li {
background: #fff;
list-style: none;
display: inline-block;
margin: 0 25px;
font-size: 12px;
}
.socialIcons li a {
text-decoration: none;
color: #000;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<ul class="socialIcons">
<li class="particletext hearts" onclick="hearts()"><a>A</a></li>
<li class="particletext bubbles" onclick="bubbles()"><a>B</a></li>
<li class="particletext sunbeams" onclick="sunbeams()"><a>C</a></li>
<li class="particletext confetti" onclick="confetti()"><a>D</a></li>
<li class="particletext fire" onclick="fire()"><a>E</a></li>
</ul>