• 运动——淡入淡出


    一、一个DIV设置淡入淡出

    代码:


    <!DOCTYPE HTML>
    <html>
    <head>

    <meta charset="utf-8">
    <title>运动--淡入淡出</title>
    <!-- <link href="test_css.css" rel="stylesheet" type="text/css">
    <script type="text/javascript" src="test.js"></script>-->
    <style>
    #div {
    200px;
    height: 200px;
    background: #ff2e1d;
    position: absolute;
    left: 100px;
    top: 100px;
    opacity: 0.3;
    filter: alpha(opacity:30);
    <!-- 仅支持IE浏览器 -->

    }

    </style>
    <script>
    window.onload = function () {
    var oDiv = document.getElementById("div");
    oDiv.onmouseover = function () {
    startMove(100);
    };

    oDiv.onmouseout = function () {
    startMove(30);
    };

    var alpha = 30;
    var timer = null;

    function startMove(iTarget) {
    clearInterval(timer);
    timer = setInterval(function () {
    var speed = 0;
    if (alpha < iTarget) {
    speed = 10;
    } else {
    speed = -10;
    }

    if (alpha == iTarget) {
    clearInterval(timer);
    } else {
    alpha += speed;
    oDiv.style.filter = 'alpha(opacity:' + alpha + ')';
    oDiv.style.opacity = alpha / 100;
    }
    }, 30);


    }
    }

    </script>
    </head>
    <body>
    <div id="div"></div>


    </body>
    </
    html>

    运行结果:

     初始:

    鼠标移入:

    鼠标移出:

    二、多个DIV设置淡入淡出

    代码:

    
    
    <!DOCTYPE HTML>
    <html>
    <head>
    <meta charset="utf-8">
    <title>无标题文档</title>
    <style>
    div {200px; height:200px; margin:20px; float:left; background:red; filter:alpha(opacity:30); opacity:0.3;}
    </style>
    <script>
    window.onload=function ()
    {
    var aDiv=document.getElementsByClassName("e");

    for(var i=0;i<aDiv.length;i++)
    {
    aDiv[i].alpha=30;

    aDiv[i].onmouseover=function ()
    {
    startMove(this, 100);
    };
    aDiv[i].onmouseout=function ()
    {
    startMove(this, 30);
    };
    }
    };


    function startMove(obj, iTarget)
    {
    clearInterval(obj.timer);
    obj.timer=setInterval(function (){
    var speed=(iTarget-obj.alpha)/6;
    speed=speed>0?Math.ceil(speed):Math.floor(speed);

    if(obj.alpha==iTarget)
    {
    clearInterval(obj.timer);
    }
    else
    {
    obj.alpha+=speed;

    obj.style.filter='alpha(opacity:'+obj.alpha+')';
    obj.style.opacity=obj.alpha/100;
    }
    }, 30);
    }
    </script>
    </head>

    <body>
    <div class="e"></div>
    <div class="e"></div>
    <div class="e"></div>
    <div class="e"></div>
    </body>
    </
    html>
     
  • 相关阅读:
    P2832 行路难
    P2634 [国家集训队]聪聪可可
    模拟退火算法
    洛谷 P2986 [USACO10MAR]Great Cow Gat…(树形dp+容斥原理)
    bzoj1040: [ZJOI2008]骑士(基环树dp)
    洛谷P2014 选课(树形dp)
    洛谷P3047 [USACO12FEB]Nearby Cows(树形dp)
    bzoj1026: [SCOI2009]windy数(数位dp)
    hdu3555Bomb(数位dp)
    hdu3652B-number(数位dp)
  • 原文地址:https://www.cnblogs.com/theWayToAce/p/5264271.html
Copyright © 2020-2023  润新知