0
我正在制作一个脚本,它在单击时旋转图标class =“glyphicon glyphicon-star”。单击时图标不旋转
这里是CSS代码
.glyphicon-star-animate {
-webkit-animation-name: rotateThis;
-webkit-animation-duration: 2s;
-webkit-animation-iteration-count: infinite;
-webkit-animation-timing-function: linear;
}
@-webkit-keyframes "rotateThis" {
from {
-webkit-transform: rotate(0deg);
}
to {
-webkit-transform: rotate(360deg);
}
}
这里是jQuery代码:
$(document).ready(function() {
$("#update").on("click", function(e) {
var $icon = $(this).find(".glyphicon.glyphicon-star"),
animateClass = "glyphicon-star-animate";
$icon.addClass(animateClass);
// setTimeout is to indicate some async operation
window.setTimeout(function() {
$icon.removeClass(animateClass);
}, 2000);
});
});
下面是HTML代码:
<a id="update" href="#"><i class="glyphicon glyphicon-star"></i></a>
我的项目包括显示几个divs(使用php的fetcharray loop函数从数据库中提取)在)里面有不同的内容。 但我使用的glyphicon glyphicon-star在每个div中都可以看到。我的问题是旋转函数或jquery只能在第一个div上运行。第二个div或后续的类=“glyphicon glyphicon-star”不会单独旋转。我怎样才能让他们独立旋转?
非常感谢。是!它现在正在工作! – Sayuj3
很高兴听到这个消息。 :)祝你好运 –
谢谢你@Mostafa Baezid – Sayuj3