• js动画实例


    <!--<!doctype html>
    <html>
    <head>
    <meta charset="utf-8">
    <meta name="author" content="http://www.softwhy.com/" />
    <style type="text/css">
    </style>
    </head>
    <body>
    <div style="position:absolute;left:0;top:0;50px;height:50px;background-color:blue;"></div>
    <script type="text/javascript">
        var div=document.getElementsByTagName('div')[0];
        var disX,
            disY;
            div.onmousedown=function(e){
                disX=e.pageX-parseInt(div.style.left);
                disY=e.pageY-parseInt(div.style.top);
                document.onmousemove=function(e){
                    var event=e||window.event;
                    div.style.left=e.pageX-disX+"px";
                    div.style.top=e.pageY-disY+"px";
                }
                document.onmouseup=function(){
                    div.onmousemove=null;
                }
            }
    </script>
    </body>
    </html>-->
    <!DOCTYPE html>
    <html lang="en">
    <meta charset="utf-8">
    <style>
      *{
          margin:0px;
          padding:0px;
      }
      div{
          100px;
          height:100px;
          background-color:black;
          left:0;
          top:0;
          position:absolute;
          opacity:1;
      }
    </style>
    <body>
    <div></div>
    <script>
    var div=document.querySelector('div');
    animate(div,{
        200,
        left:500,
        opacity:20
    });
     function animate(el,properties){
         clearInterval(el.timerId);
         el.timerId=setInterval(function(){
             for(var property in properties){
                 var current;
                 var target=properties[property];
                 if(property==='opacity'){
                     current=Math.round(parseFloat(getstyle(el,'opacity'))*100);
                 }else{
                     current=parseInt(getstyle(el,property));
                 }
             var speed=(target-current)/30;
             speed=speed>0?Math.ceil(speed):Math.floor(speed);
               if(property==='opacity'){
                   el.style.opacity=(current+speed)/100;
               }else{
               el.style[property]=current+speed+'px';
               }
         }
         },20)
     }
     function getstyle(el,property){
          if(getComputedStyle){
              return getComputedStyle(el)[property]
          }else{
              return el.currentStyle[property];
          }
      }
    </script>
    </body>
    </html>
  • 相关阅读:
    ABP官方文档翻译 3.4 领域服务
    ABP官方文档翻译 3.3 仓储
    ABP官方文档翻译 3.2 值对象
    ABP官方文档翻译 3.1 实体
    ABP官方文档翻译 2.7 对象到对象的映射
    ABP官方文档翻译 2.6 定时
    bootstrap 源码中部分不了解的css属性
    vue 父组件调用子组件事件/子组件调用父组件方法
    js性能优化问题学习笔记
    js递归性能影响及解决方案
  • 原文地址:https://www.cnblogs.com/hunter1/p/13042059.html
Copyright © 2020-2023  润新知