蓝色动力网络

 找回密码
 立即注册

扫一扫,访问微社区

QQ登录

只需一步,快速开始

查看: 3642|回复: 0

[JS效果]动画效果打开/关闭层

[复制链接]
发表于 2008-7-13 17:13:41 | 显示全部楼层 |阅读模式
[JS效果]动画效果打开/关闭层



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>DOM_text01</title>
<style type="text/css">
body,span,div,td{font-size:12px;line-height:1.5em;color:#849BCA;}
#bodyL{
        float:left;
        width:84px;
        margin-right:2px;
}
a.od{
        width:80px;
        height:25px;
        line-height:25px;
        text-align:center;
        font-weight:bold;
        border: 2px solid #849BCA;       
        display:block;
        color:#547BC9;
        float:left;
        text-decoration:none;
        margin-top:2px;
}
a.od:link{
        background:#EEF1F8;
}
a.od:visited{
        background:#EEF1F8;
}
a.od:hover{
        background:#EEE;
}
a.od:active{
        background:#EEE;
}
#fd{       
        width:500px;
        height:200px;
        background:#EDF1F8;       
        border: 2px solid #849BCA;
        margin-top:2px;
        margin-left:2px;
        float:left;
        overflow:hidden;
        position:absolute;
        left:0px;
        top:0px;
        cursor:move;
        float:left;
        /*filter:alpha(opacity=50);*/
       
}
.content{
        padding:10px;
}
</style>
</head>
<body>
<div id="bodyL">
        <a href="#" class="od" onclick = "show('fd');return false;">
                [打开层]
        </a>
        <a href="#" class="od" onclick = "closeed('fd');return false;">
                [关闭层]
        </a>
</div>       
<div id="fd" style="display:none;filter:alpha(opacity=100);opacity:1;">
        <div class="content">移动层</div>       
</div>
       
<script type="text/javascript">
        var prox;
        var proy;
        var proxc;
        var proyc;
        function show(id){/*--打开--*/
                clearInterval(prox);
                clearInterval(proy);
                clearInterval(proxc);
                clearInterval(proyc);
                var o = document.getElementById(id);
                o.style.display = "block";
                o.style.width = "1px";
                o.style.height = "1px";
                prox = setInterval(function(){openx(o,500)},10);
        }       
        function openx(o,x){/*--打开x--*/
                var cx = parseInt(o.style.width);
                if(cx < x)
                {
                        o.style.width = (cx + Math.ceil((x-cx)/5)) +"px";
                }
                else
                {
                        clearInterval(prox);
                        proy = setInterval(function(){openy(o,200)},10);
                }
        }       
        function openy(o,y){/*--打开y--*/       
                var cy = parseInt(o.style.height);
                if(cy < y)
                {
                        o.style.height = (cy + Math.ceil((y-cy)/5)) +"px";
                }
                else
                {
                        clearInterval(proy);                       
                }
        }       
        function closeed(id){/*--关闭--*/
                clearInterval(prox);
                clearInterval(proy);
                clearInterval(proxc);
                clearInterval(proyc);               
                var o = document.getElementById(id);
                if(o.style.display == "block")
                {
                        proyc = setInterval(function(){closey(o)},10);                       
                }               
        }       
        function closey(o){/*--打开y--*/       
                var cy = parseInt(o.style.height);
                if(cy > 0)
                {
                        o.style.height = (cy - Math.ceil(cy/5)) +"px";
                }
                else
                {
                        clearInterval(proyc);                               
                        proxc = setInterval(function(){closex(o)},10);
                }
        }       
        function closex(o){/*--打开x--*/
                var cx = parseInt(o.style.width);
                if(cx > 0)
                {
                        o.style.width = (cx - Math.ceil(cx/5)) +"px";
                }
                else
                {
                        clearInterval(proxc);
                        o.style.display = "none";
                }
        }       
       
       
        /*-------------------------鼠标拖动---------------------*/       
        var od = document.getElementById("fd");       
        var dx,dy,mx,my,mouseD;
        var odrag;
        var isIE = document.all ? true : false;
        document.onmousedown = function(e){
                var e = e ? e : event;
                if(e.button == (document.all ? 1 : 0))
                {
                        mouseD = true;                       
                }
        }
        document.onmouseup = function(){
                mouseD = false;
                odrag = "";
                if(isIE)
                {
                        od.releaseCapture();
                        od.filters.alpha.opacity = 100;
                }
                else
                {
                        window.releaseEvents(od.MOUSEMOVE);
                        od.style.opacity = 1;
                }               
        }
       
       
        //function readyMove(e){       
        od.onmousedown = function(e){
                odrag = this;
                var e = e ? e : event;
                if(e.button == (document.all ? 1 : 0))
                {
                        mx = e.clientX;
                        my = e.clientY;
                        od.style.left = od.offsetLeft + "px";
                        od.style.top = od.offsetTop + "px";
                        if(isIE)
                        {
                                od.setCapture();                               
                                od.filters.alpha.opacity = 50;
                        }
                        else
                        {
                                window.captureEvents(Event.MOUSEMOVE);
                                od.style.opacity = 0.5;
                        }
                       
                        //alert(mx);
                        //alert(my);
                       
                }
        }
        document.onmousemove = function(e){
                var e = e ? e : event;
               
                //alert(mrx);
                //alert(e.button);               
                if(mouseD==true && odrag)
                {               
                        var mrx = e.clientX - mx;
                        var mry = e.clientY - my;       

                        od.style.left = parseInt(od.style.left) +mrx + "px";
                        od.style.top = parseInt(od.style.top) + mry + "px";                       
                        mx = e.clientX;
                        my = e.clientY;
                       
                }
        }
       
       
</script>
</body>
</html>
   提示:您可以先修改部分代码再运行
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

蓝色动力网络微信平台
网站管理,业务合作联系邮箱: admin#lansedongli.com    QQ:13412492 限网站业务问题.
网站帐号、密码、密保找回请使用注册邮箱,发送邮件至 password#lansedongli.com ,否则不予受理.
免责声明:本论坛所有文字和图片仅代表其个人观点.
本站某些资料或文章来自于互联网,不代表本站观点,如果侵犯了您的权益,请来信告知,我们会在三天内删除.
为了给大家一个更好的交流场所,请勿在本论坛发表与中华人民共和国法律相抵触的言论,请合作,谢谢!
Copyright © 2007-2019 Corporation Powered by网吧系统 版权所有    转载请注明!
浙ICP备11043737号-1 程序:Discuz! x3.4

湘公网安备 43018102000145号

手机版|Archiver|蓝色动力网络   

快速回复 返回顶部 返回列表