zoukankan      html  css  js  c++  java
  • 完美运动框架


    <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>

    在程序媛的路上,越走越用劲儿:)
  • 相关阅读:
    django创建项目,一个简单的登录。
    MySQL下载与安装
    查看拉去代码时候的git账号密码
    Springmvc-组件
    转发与重定向
    springMVC-常用注解
    springMVC-请求参数绑定
    SpringMVC-RequestMapping注解
    JAVA-异常处理
    springMVC-入门案例
  • 原文地址:https://www.cnblogs.com/AliceX-J/p/4636193.html
Copyright © 2011-2022 走看看