zoukankan      html  css  js  c++  java
  • css3 移动端旋转动画暂停

     音乐播放图片旋转动画 ios不支持暂停: animation-play-state: paused;

    @-webkit-keyframes rotate{
        100% {
               transform: rotate(1turn);
            }
    }
    .img-wrapper{
        width: 200px;    
        height: 200px;
        margin: 50px auto 0;
        overflow: hidden;
        border-radius: 100px;
    }
    .animation-start{
        animation: rotate 5s linear infinite;
    }
    .suspended{
        animation-play-state: paused;
    }
    .img-wrapper img{
        width: 100%;
        border-radius: 100px;
    }
    .btn{
        width: 100%;
        height: 30px;
        box-sizing: border-box;
        text-align: center;
        margin-top: 20px;
        line-height: 30px;
        bottom: 100px;
        border: 1px solid #ccc;
    }

     html

    1 <div class="img-wrapper">
    2     <img src="http://img001.ddweilai.com/mtrain/2018/03/5ab3630ccbd9e.jpg"/>
    3 </div>
    4 <div class="btn">按钮</div>

    js

     1 var isIPHONE = navigator.userAgent.toUpperCase().indexOf('IPHONE')!= -1;
     2 var isPlaying = false;
     3 var imgWrapper = $(".img-wrapper")[0];
     4 var img = $('.img-wrapper').find('img')[0];
     5 function pause() {
     6     isPlaying = false;
     7     var iTransform = getComputedStyle(img).transform;
     8     var cTransform = getComputedStyle(imgWrapper).transform;
     9      imgWrapper.style.transform = cTransform === 'none'
    10                  ? iTransform
    11                  : iTransform.concat(' ', cTransform);
    12                   $(img).removeClass('animation-start');
    13 }
    14 function play() {
    15     isPlaying = true;
    16     $(img).addClass('animation-start');
    17 }
    18 if(!isIPHONE){
    19     $(imgWrapper).addClass('animation-start').addClass('suspended');
    20 }
    21 $(".btn").click(function(){
    22     if(isIPHONE){
    23         isPlaying ? pause() : play();
    24     }else{
    26          if($(imgWrapper).hasClass('suspended')){
              $(imgWrapper).removeClass('suspended');
    29         }else{
    30              $(imgWrapper).addClass('suspended');
    32         }
    33     }
    34 });
  • 相关阅读:
    poj 3667 Hotel
    codevs 1380 没有上司的舞会
    bzoj 4033 树上染色
    bzoj 1179 [APIO 2009]Atm(APIO水题)
    poj 1741 Tree
    bzoj 3600 没有人的算术
    poj 3233 Matrix Power Series
    hdu 2256 Problem of Precision -矩阵快速幂
    [矩阵十题第七题]vijos 1067 Warcraft III 守望者的烦恼 -矩阵快速幂
    main函数递归
  • 原文地址:https://www.cnblogs.com/lvshaonan/p/9009891.html
Copyright © 2011-2022 走看看