How to pass css :active pseudo class to javascript?

后端 未结 2 1318
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-10 08:34

Reference: Comments posted by @AnkithAmtange


Given html

Click Away

css

div {
  width:          


        
2条回答
  •  抹茶落季
    2020-12-10 09:27

    You can utilize :active:hover pseudo class, animation with duration set to 0s, @keyframes at css; animationend event at javascript

    :root {
      --activeprop: 0px;
    }
    div {
      position: relative;
      left: var(--activeprop);
      width: 200px;
      height: 200px;
      background: orange;
    }
    div:active:hover {
      color: white;
      background: rebeccapurple;
      animation: active 0s;
      -moz-animation: active 0s;
      -webkit-animation: active 0s;
    }
    
    @keyframes active {
      from {
        left:var(--activeprop);
      }
      to {
        left:var(--activeprop);
      }
    }
    
    @-moz-keyframes active {
      from {
        left:var(--activeprop);
      }
      to {
        left:var(--activeprop);
      }
    }
    @-webkit-keyframes active {
      from {
        left:var(--activeprop);
      }
      to {
        left:var(--activeprop);
      }
    }
    Click Away

提交回复
热议问题