• 动画解决方案(二)


    上篇博客做的动画解决了我banner卡顿的问题,但之前还试了用jquery的animation,虽然依然卡顿,但不失为一种方法。

    1.jquery的animation

    <!DOCTYPE html>
    <html>
    <head>
      <meta charset="utf-8">
      <title>进度条</title>
      <script src="http://static.runoob.com/assets/jquery-validation-1.14.0/lib/jquery.js"></script>
      <style type="text/css">
        .container{
           50px;
          margin: 50px;
        }
        .progressBar {
          display: inline-block;
           81%;
          height: 22px;
          background-color: rgba(0,0,0);
          margin-right: 3%;
        }
        #progressFill {
           0%;
          height: 22px;
          position: relative;
          background-color: red;
          background-size: 3em 3em;
          animation: warning-animation 750ms infinite linear;
        }
      
      @keyframes warning-animation {
          0% {
              background-position: 0 0;
          }
          100% {
              background-position: 3em 0;
          }
      }
      .progressText, #percentage {
        display: inline-block;
        margin-top: -11px;
        vertical-align: middle;
      }
      </style>     
    </head>
    <body>
      <button id = "begin">点击开始</button>
      <div class="container">
        <span class = "progressBar">
          <div id = "progressFill"></div>
        </span>
        <span class = "progressText"> 进度  </span>
        <span id = "percentage">0%</span>
      </div>  
    </body>
    <script>
      $("#begin").on("click",function(){
        $("#progressFill").animate({ 
           "100%"
        }, 8000);
        
      })
    </script>
    </html>

    2.出了这个,还可以使用js控制width,(但也会出现卡顿,这种要保证width每42ms改变一次)。

    let pro = 0;
    this.timer = setInterval(function () {
        if (pro < 50) {
            pro++;
        } else {
            clearInterval(this.timer_i);
        }
        if (slider.currentSlide !== i) {
            pro = 0;
        }
        bar.width(pro + "px");
    }, 160);
  • 相关阅读:
    正则判断手机号是不是11位
    jQuery, js 验证两次输了密码的一相同
    数据库读取图片
    使用 jQuery 修改 css 中带有 !important 的样式属性
    PHP去掉最后一个字符
    按钮
    js 实现两种99乘法表
    PHP 各种循环
    thinkphp的空控制器和空操作以及对应解决方法
    ThinkPHP框架知识
  • 原文地址:https://www.cnblogs.com/kaiqinzhang/p/10450118.html
Copyright © 2020-2023  润新知