zoukankan      html  css  js  c++  java
  • 多物体运动3(最终的运动框架)

    <!DOCTYPE html>
    <html>

    <head>
    <meta charset="UTF-8">
    <title></title>
    <style>
    div {
    150px;
    height: 150px;
    background: red;
    float: left;
    margin: 10px;
    font-size: 8px;
    filter: alpha(opacity: 30);
    opacity: 0.3;
    }
    </style>
    <script>
    var timer = null;
    window.onload = function() {

    //******************************************
    var div1 = document.getElementById('div1');
    div1.timer = null;
    div1.onmouseover = function() {
    startMove(div1, 'opacity', 100);
    }
    div1.onmouseout = function() {
    startMove(div1, 'opacity', 30);
    }
    };

    function getStyle(obj, name) {
    if(obj.currentStyle) {
    return obj.currentStyle[name];
    } else {
    return getComputedStyle(obj, false)[name];
    }
    }

    function startMove(obj, element, target) {
    clearInterval(obj.timer);

    obj.timer = setInterval(function() {
    var crrent = 0;
    //增加if else语句,判断opacity
    if(element == 'opacity') {
    //round四舍五入
    crrent = Math.round(parseFloat(getStyle(obj, element))*100);
    } else {
    crrent = parseInt(getStyle(obj, element));
    }

    var speed = (target - crrent) / 5500;
    speed = speed > 0 ? Math.ceil(speed) : Math.floor(speed);

    if(crrent == speed) {
    clearInterval(obj.timer);
    } else {
    if(element == 'opacity') {
    obj.style.filter = 'alpha(opacity:' + (crrent + speed)+ ')';
    obj.style.opacity = (crrent + speed) / 100;
    } else {
    obj.style[element] = crrent + speed + 'px';
    }
    }
    }, 30);
    }
    </script>
    </head>

    <body>
    <div id="div1"></div>
    </body>

    </html>

  • 相关阅读:
    ajax提交Form
    MySQL新建用户,授权,删除用户,修改密码总结
    php 数组操作类(整合 给意见)
    PHP基于数组的分页函数(核心函数array_slice())
    php生成table表格
    百度地图定位
    python-redis-订阅和发布
    宿主机-免密登录Docker容器
    docker-文件系统出错处理
    python-redis集合模式
  • 原文地址:https://www.cnblogs.com/youcandomore/p/6723096.html
Copyright © 2011-2022 走看看