(function(){
$(".button").on("click", function(e){
var yOffset = e.pageY - $(this).offset().top;
var xOffset = e.pageX - $(this).offset().left;
var self = this;
var xPos = parseInt(xOffset);
var yPos = parseInt(yOffset);
$(this).find("svg").remove();
$(this).append('<svg><circle cx="'+xPos+'" cy="'+yPos+'" r="'+0+'"></circle></svg>');
var c = $(self).find("circle");
c.animate(
{
"r" : $(self).outerWidth()
},
{
easing: "easeOutQuad",
duration: 500,
step : function(val){},
complete : function(){c.css( "r", "0" );}
}
);
});
}());
.button {
position: relative;
display: inline-block;
height: 40px;
padding: 0 20px;
margin: 0;
background: transparent;
border: none;
color: rgb(0,0,0,0);
font-size: 20px;
font-weight: 900;
text-align: center;
text-transform: uppercase;
-webkit-tap-highlight-color: transparent;
}
.button:hover {
background-color: rgba(158,158,158,0.10);
}
.button:active,
.button:focus {
background-color: rgba(158,158,158, 0.30);
outline: 0;
}
.button svg {
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
}
.button circle {
fill: rgba(0,0,0,0.50);
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Reset jQuery animation when it stops animating</title>
</head>
<body>
<button class="button">Button</button>
<script src="https://code.jquery.com/jquery-2.2.4.min.js" integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" crossorigin="anonymous"></script>
<script src='http://cdnjs.cloudflare.com/ajax/libs/jquery-easing/1.3/jquery.easing.min.js'></script>
</body>
</html>
complete: function(){ c.css("r", "");}
是不行的,我已经编辑了我的答案,回调应该是complete: function(){ c.css("r", 0);}
。 - Aung Myo Linn$( "#mydiv" ).css( "color", "" )
- 可以从元素中移除属性,但在 JSBin 上显然无法工作。 - Aung Myo Linncomplete : function(){c.css( "r", "0" );}
吗? - Aung Myo Linn