• 多物体运动2(几种运动共用一套)


    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title></title>
    <style>
    div{
    150px;
    height: 150px;
    background: red;
    float: left;
    margin: 10px;
    font-size: 8px;

    }
    </style>
    <script>
    var timer = null;
    window.onload = function(){

    //***********************************************************
    var div1 = document.getElementById('div1');
    div1.timer = null;
    div1.onmouseover = function(){
    startMove(div1,'width',500);
    }
    div1.onmouseout = function(){
    startMove(div1,'width',150);
    }

    //***********************************************************
    var div2 = document.getElementById('div2');
    div2.timer = null;
    div2.onmouseover = function(){
    startMove(div2,'height',500);
    }
    div2.onmouseout = function(){
    startMove(div2,'height',150);
    }

    //***********************************************************
    var div3 = document.getElementById('div3');
    div3.timer = null;
    div3.onmouseover = function(){
    startMove(div3,'font-size',50);
    }
    div3.onmouseout = function(){
    startMove(div3,'font-size',10);
    }


    };

    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 = parseInt(getStyle(obj,element));
    var speed = (target-crrent)/6;
    speed = speed>0?Math.ceil(speed):Math.floor(speed);

    if(crrent == speed){
    clearInterval(obj.timer);
    }else{
    obj.style[element] = crrent + speed +'px';
    }
    },30);
    }

    </script>
    </head>
    <body>
    <div id="div1">变宽</div>
    <div id="div2">变高</div>
    <div id="div3">字体变化</div>

    </body>
    </html>

  • 相关阅读:
    三种解决IE版本兼容性问题
    CSS 如何让超链接访问后和访问前的颜色不同且访问后仍保留hover和active效果
    bootstrap 笔记用法
    STL优缺点
    输出最大回文数
    将一组单词逆序输出
    排序算法
    背包问题
    二进制
    sstream
  • 原文地址:https://www.cnblogs.com/youcandomore/p/6679446.html
Copyright © 2020-2023  润新知