js 点击刷新的按钮执行动画 (转一圈)

css 代码:

/* 刷新按钮 */

.refresh {
    width: 32px;
    height: 32px;
    position: relative;
    top: -2px;
}

/* 刷新动画 */

  @-webkit-keyframes rotation {

from {
    -webkit-transform: rotate(0deg);
}

to {
    -webkit-transform: rotate(360deg);
}

  }

@keyframes rotation {
    from {
        -webkit-transform: rotate(0deg);
        transform: rotate(0deg)
    }

to {
    -webkit-transform: rotate(360deg);
    transform: rotate(360deg)
}

}

html 代码:

<img class="refresh" src="./img/refresh.png" alt="">

js 代码:

$(".refresh").on('click', function () {
    $(this).css("-webkit-animation", "rotation 1s ease-out 1");
    $(this).css("-ms-animation", "rotation 1s ease-out 1");
    $(this).css("animation", "rotation 1s ease-out 1");
    var z = $(this);
    setTimeout(function () {
        $(z).css("animation", "");
    }, 1000);
});
posted @ 2020-04-03 17:09  严格的阿b  阅读(2324)  评论(0编辑  收藏  举报