CSS图片旋转/暂停后保持旋转状态(音乐播放常用)

html

      <div @click="()=>{noMusic=false;palyAudio()}" v-if="noMusic">
          <img src="../../assets/pic/activitiy/noMus.png" alt="" style="width: 
           30px;height:30px;border-radius: 30px;">
      </div>
      <div @click="palyAudio" v-if="!noMusic">
          <img src="../../assets/pic/activitiy/music.png" alt="" style="width: 
          30px;height:30px;border-radius: 30px;" :class=" 
          {'rot_img':plyMus,'pus_img':plyPus}">
      </div>

js

  data() {
    return {
      noMusic:true,// 是否显示静音图标
      playAdo:false,//判断音频是否是播放状态
      plyMus:false,//播放音频
      plyPus:false//暂停音频
    };
  },

    palyAudio(){   
      let buttonAudio = document.getElementById('eventAudio');
      if(!this.playAdo){
        buttonAudio.play();
        this.plyPus = false;
        this.plyMus = true;
        this.playAdo = !this.playAdo
      }else{
        buttonAudio.pause();
        this.plyPus = true;
        this.playAdo = !this.playAdo
      }
      
    },

css

.pus_img{
  animation-play-state: paused !important;
  -webkit-animation-play-state: paused !important;
}
@keyframes rotation{

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

.rot_img{

    -webkit-transform: rotate(360deg);
    animation: rotation 7s linear infinite;
    -moz-animation: rotation 7s linear infinite;
    -webkit-animation: rotation 7s linear infinite;
    -o-animation: rotation 7s linear infinite;

}

然后呈现的效果是用户刚进入页面是静音

再点击这个静音标以后静音.png隐藏显示音乐.png,并触发旋转事件开始旋转

 

这样再点击音乐旋转标以后会停留在旋转位置 不会位置归0 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值