zoukankan      html  css  js  c++  java
  • 运动——淡入淡出

    一、一个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>
     
  • 相关阅读:
    centos7最小化安装无法tab补全
    rhcsa备战笔记
    idea springboot应用启动
    idea 导入Mapper错误报错设置
    idea 忽略显示文件
    maven 插件jetty/tomcat启动 web 应用
    maven jstl、jsp、servlet依赖
    maven 项目目录图与web 应用结构图对比
    maven 远程仓库、私服及镜像配置
    maven windows环境nexus3.0私服搭建
  • 原文地址:https://www.cnblogs.com/theWayToAce/p/5264271.html
Copyright © 2011-2022 走看看