zoukankan      html  css  js  c++  java
  • loading加载动画效果js实现

    <style>
    .box { 400px; padding: 20px; border: 40px solid #a0b3d6; background-color: #eee; overflow: hidden; }
    .loading { height: 100%; background: url(images/loading.gif) no-repeat center; }
    .in { 100px; margin: 0 auto; border: 50px solid #beceeb; background-color: #f0f3f9; }
    [type=button] { 100px; height: 32px; font-size: 100%; }
    </style>
    </head>

    <body>
      <div id="main">
        <div id="effect" class="part">
          <div class="show">
            <div class="demo">
              <div id="box" class="box">
              </div>
              <p>
                <input type="button" id="button" value="点击我">
              </p>
            </div>
          </div>
        </div>
       </div>
    </div>

    <script>
    // 高度无缝动画方法
    var funTransitionHeight = function(element, time) { // time, 数值,可缺省
    if (typeof window.getComputedStyle == "undefined") return;
    var height = window.getComputedStyle(element).height;
    element.style.transition = "none"; // 本行2015-05-20新增,mac Safari下,貌似auto也会触发transition, 故要none下~
    element.style.height = "auto";
    var targetHeight = window.getComputedStyle(element).height;
    element.style.height = height;
    element.offsetWidth = element.offsetWidth;
    if (time) element.style.transition = "height "+ time +"ms";
    element.style.height = targetHeight;
    };

    (function() {
    // demo演示脚本
    var box = document.getElementById("box"), button = document.getElementById("button");
    button.onclick = function() {
    // 载入菊花,模拟loading效果
    box.innerHTML = '<div class="loading"></div>';
    // 随机高度内容
    setTimeout(function() {
      box.innerHTML = '<div class="in" style="height:'+ Math.round(400 * Math.random()) +'px;"></div>';
      funTransitionHeight(box, 250);
      }, 1000);
    };

    // 初始高度
    funTransitionHeight(box);
    })();
    </script>

    </body>

  • 相关阅读:
    python之json&pickle
    python之装饰器
    软件测试基础
    软件测试分类
    python3文件的读写操作
    python3对excel文件读写操作
    Java集合整理
    mybatis一对多关系的关联查询
    用xftp从win7系统传输一些必要的文件到Linux
    Spring和Mybatis的整合
  • 原文地址:https://www.cnblogs.com/yzhihao/p/6479187.html
Copyright © 2011-2022 走看看