zoukankan      html  css  js  c++  java
  • CSS3 animation小动画

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>Examples</title>
    <meta name="description" content="">
    <meta name="keywords" content="">
    <link href="" rel="stylesheet">
    <style>
        *{
            padding: 0;
            margin: 0;
        }
        .btn{
             200px;
            text-align: center;
        }
        .test{
             90px;
            height: 60px;
            background: url(img/test.png) no-repeat;
            margin: 60px;
            /*-webkit-animation: run 350ms steps(1) infinite 0s;*/
            -webkit-animation: run 350ms steps(5) infinite 0s;
        }
        /*@-webkit-keyframes run{
            0%{
                background-position: 0;
            }
            20%{
                background-position: -90px 0;
            }
            40%{
                background-position: -180px 0;
            }
            60%{
                background-position: -270px 0;
            }
            80%{
                background-position: -360px 0;
            }
            100%{
                background-position: -450px 0;
            }
        }*/
        @-webkit-keyframes run{
            100%{
                background-position: -450px 0;
            }
        }
    </style>
    <script>
        var speed =350;
        var flag = true;
        function fast(){
            var obj = document.getElementById('flash');
            speed-=10;
            // console.log(obj.style.webkitAnimation) //为何获取不到??????
            obj.style.webkitAnimation = " run "+speed+"ms steps(5) infinite 0s"
        }
        function slow(){
            var obj = document.getElementById('flash');
            speed+=10;
            // console.log(obj.style.webkitAnimation) //为何获取不到??????
            obj.style.webkitAnimation = " run "+speed+"ms steps(5) infinite 0s"
        }
        function play(){
            var obj = document.getElementById('flash');
            flag = !flag;
            obj.style.webkitAnimationPlayState = flag ? "running" : "paused";
        }
    </script>
    </head>
    <body>
        <div id='flash' class="test"></div>
        <div class="btn"><button onclick="fast()">跑快点</button> <button onclick="slow()">跑慢点</button> <button onclick="play()">暂停/开始</button></div>
    </body>
    </html>

    效果图

    源码下载

  • 相关阅读:
    2015-05-06前端开发总结
    深入了解 Flexbox 伸缩盒模型
    Sublime text3 快捷方式(windows平台)
    移动web最简洁的滑动效果Swipe JS(适合初学者)
    谈响应式web设计代码实现
    经验分享:多屏复杂动画CSS技巧三则
    css3 animation动画效果解析
    移动H5前端性能优化指南
    php codeigniter (CI) oracle 数据库配置-宋正河整理
    jquery图片裁切+PHP文件上传
  • 原文地址:https://www.cnblogs.com/JerryWang24/p/5586731.html
Copyright © 2011-2022 走看看