loop gradient directions by clicking on a target

前端 未结 3 1488
借酒劲吻你
借酒劲吻你 2021-01-29 02:11

I need to loop all of the eight gradient directions by clicking on a target, like this:

3条回答
  •  我在风中等你
    2021-01-29 02:39

    Don't over complicate it, make it simple:

    var c=0;
    
    document.querySelector('.targ').addEventListener('click',function(e) {
      e.target.style.setProperty('--d',(c+=90)+"deg");
    })
    .targ {
      width: 54px;
      height: 54px;
      cursor: pointer;
      background: linear-gradient(var(--d,0deg),red,yellow)
    }

提交回复
热议问题