简体   繁体   English

CSS:转换一次转换,然后将其重置而不转换

[英]CSS: transition a transformation once, then reset it without transition

Basically I want to transition my element by adding a class .anim every 5 seconds but reset it ever 1 second w/o transitioning the property. 基本上,我想通过每5秒添加一个类.anim来转换元素,但是每1秒钟重置一次,而.anim转换属性。

The effect I want is to spin the arrow around once every 5 seconds. 我想要的效果是每5秒旋转一次箭头。

What's the best way to do this? 最好的方法是什么?

setInterval(function(){
    var $el = $("a.inbox");

    $el.addClass('anim');
    setTimeout(function(){
        $el.removeClass('anim');
    }, 1000);
    console.log($el);
}, 5000);

a.inbox:before {
  content: '⇧';
  display: inline-block;
  position: relative;
  -webkit-transform: rotate(180deg);
  margin-left: 5px;

  transition: -webkit-transform 1s;
}

a.inbox {
  &.anim:before {
    -webkit-transform: rotate(540deg);
  }
}

<a href="#" class="inbox">Inbox</a>

Only put the transition property inside the a.inbox.anim style. 只将transition属性放在a.inbox.anim样式内。 This will mean that the transition is only applied when changing to that class, but won't be applied when it is removed. 这意味着仅在更改为该类时才应用过渡,而在移除过渡时将不应用过渡。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM