• 完美运动框架



    <html>
    <head>
    <meta charset="utf-8">
    <style>
    #div1 {
    200px;
    height:200px;
    background:#ff0
    }
    </style>
    <script>
    //让多个值同时变化
    //jason传n个改变样式


    //获取样式
    function getStyle(obj,attr)
    {
    if(obj.currentStyle)
    {
    return obj.currentStyle[attr];
    }
    else
    {
    return getComputedStyle(obj,false)[attr];
    }
    }
    //运动
    function starMove(obj,json,fn)
    {
    clearInterval(obj.timer);
    obj.timer=setInterval(function()
    {
    var bStop=true; //假设所有运动都到位置了
    //获取当前值
    for(var attr in json)
    {

    var iCur=0;
    if(attr=="opacity")
    {
    iCur=parseInt(parseFloat(getStyle(obj,attr))*100);
    }
    else
    {
    iCur=parseInt(getStyle(obj,attr));
    }
    //计算速度
    var iSpeed=(json[attr]-iCur)/8;
    iSpeed=iSpeed>0?Math.ceil(iSpeed):Math.floor(iSpeed);
    //检测所有的运动到达制定
    //检测所有的运动到达指定位置停止
    if(iCur!=json[attr])
    {
    bStop=false;
    }
    if(attr=="opacity")
    {
    obj.style.filter='alpha(opacity:'+(iCur+iSpeed)+')';
    obj.style.opacity=(iCur+iSpeed)/100;
    }
    else
    {
    obj.style[attr]=iCur+iSpeed+"px";
    }
    }
    if(bStop)
    {
    clearInterval(obj.timer);
    }
    if(fn)
    {
    fn();
    }
    }
    ,30)
    }
    window.onload=function(){
    var div=document.getElementById("div1");
    div.onmouseover=function(){
    starMove(div,{600,height:600});
    };
    div.onmouseout=function()
    {
    starMove(div,{200,height:200});
    };

    }
    </script>
    </head>
    <body>
    <div id="div1">
    </div>
    </body>
    </html>

    在程序媛的路上,越走越用劲儿:)
  • 相关阅读:
    剑指offer-用两个栈实现队列
    Java数组判空的正确打开方式
    浏览器输入URL后后的过程
    HTTP状态码
    HTTP和HTTPS
    北京好未来公司linux面试题
    三剑客 -- sed
    三剑客 -- grep
    shell脚本
    自动化 -- expect
  • 原文地址:https://www.cnblogs.com/AliceX-J/p/4636193.html
Copyright © 2020-2023  润新知