http://www.lanrentuku.com/lanren/jscode/js-0002/http://www.lanrentuku.com/lanren/jscode/js-0002.rar

解决方案 »

  1.   

    <!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=utf-8" />
    <title>右下角的弹窗</title>
    </head>
    <style type="text/css">
    body { background:#333333;}
    #winpop { width:200px; height:0px; position:absolute; right:0; bottom:0; border:1px solid #999999; margin:0; padding:1px; overflow:hidden;display:none; background:#FFFFFF}
    #winpop .title { width:100%; height:20px; line-height:20px; background:#FFCC00; font-weight:bold; text-align:center; font-size:12px;}
    #winpop .con { width:100%; height:80px; line-height:80px; font-weight:bold; font-size:12px; color:#FF0000; text-decoration:underline; text-align:center}
    #silu { font-size:13px; color:#999999; position:absolute; right:0;bottom:0px; text-align:right; text-decoration:underline; line-height:22px;}
    .close { position:absolute; right:4px; top:-1px; color:#FFFFFF; cursor:pointer}
    </style>
    <script type="text/javascript">
    function show_pop(){//显示窗口
      document.getElementById("winpop").style.display="block";
    timer=setInterval("changeH(4)",2);//调用changeH(4),每0.002秒向上移动一次
    }
    function hid_pop(){//隐藏窗口
    timer=setInterval("changeH(-4)",2);//调用changeH(-4),每0.002秒向下移动一次
    }
    function changeH(addH) {
    var MsgPop=document.getElementById("winpop");
    var popH=parseInt(MsgPop.style.height||MsgPop.currentStyle.height);//用parseInt将对象的高度转化为数字,以方便下面比较(JS读<style>中的height要用"currentStyle.height")
    if (popH<=100&&addH>0||popH>=4&&addH<0){//如果高度小于等于100(str>0)或高度大于等于4(str<0)
    MsgPop.style.height=(popH+addH).toString()+"px";//高度增加或减少4个象素
    }
    else{//否则
    clearInterval(timer);//取消调用,意思就是如果高度超过100象素了,就不再增长了,或高度等于0象素了,就不再减少了
    MsgPop.style.display=addH>0?"block":"none"//向上移动时窗口显示,向下移动时窗口隐藏(因为窗口有边框,所以还是可以看见1~2象素没缩进去,这时候就把DIV隐藏掉)
    }
    }
    window.onload=function(){//加载
    setTimeout("show_pop()",800);//0.8秒后调用show_pop()
    }
    </script>
    <body>
    <div id="silu">
    <br />
    <button onclick="show_pop()">测试按钮</button>
    </div>
    <div id="winpop">
    <div class="title">您有新的消息<span class="close" onclick="hid_pop()">X</span></div>
        <div class="con">未读信息(1)</div>
    </div>
    </body>
    </html>
      

  2.   


    <!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=utf-8" />
    <title>右下角的弹窗_浮动</title>
    </head>
    <style type="text/css">
    body { background:#333333;}
    #winpop { width:200px; height:0px; position:absolute; left:1px; bottom:0; border:1px solid #999999; margin:0; padding:1px; overflow:hidden;display:none; background:#FFFFFF}
    #winpop .title { width:100%; height:20px; line-height:20px; background:#FFCC00; font-weight:bold; text-align:center; font-size:12px;}
    #winpop .con { width:100%; height:80px; line-height:80px; font-weight:bold; font-size:12px; color:#FF0000; text-decoration:underline; text-align:center}
    .close { position:absolute; right:4px; top:-1px; color:#FFFFFF; cursor:pointer}
    </style><script type="text/javascript">
    /*--窗口展缩--*/
    function show_pop(){//显示窗口
      $("winpop").style.display="block";
    timer=setInterval("changeH(4)",2);
    }
    function hid_pop(){//隐藏窗口
    timer=setInterval("changeH(-4)",2);
    }
    function changeH(addH) {//窗口展缩
    var MsgPop=$("winpop");
    var popH=parseInt(MsgPop.style.height||MsgPop.currentStyle.height);
    var popT=parseInt(MsgPop.offsetTop);
    if (popH<=100&&addH>0||popH>=4&&addH<0){
    MsgPop.style.height=(popH+addH)+"px";
    MsgPop.style.top=popT-addH+"px";
    }
    else{
    clearInterval(timer);
    MsgPop.style.display=addH>0?"block":"none"
    if (addH>0)timer=setInterval(Float,1);//设置浮动
    else {clearInterval(timer);}
    }
    }
    window.onload=function(){
    setTimeout("show_pop()",500);
    }
    </script>
    <script language="JavaScript" type="text/javascript">
    /*--窗口浮动--*/function $(id){return document.getElementById(id)}
    function get_diffY(){//获取滚动条位置(顶高)值
    var diffY
    if (document.documentElement && document.documentElement.scrollTop)
    diffY = document.documentElement.scrollTop;
    else if (document.body)
    diffY = document.body.scrollTop
    else
        diffY=0
    return diffY
    }
    function get_diffH(){//获取窗口高
    var diffH
    if (document.documentElement && document.documentElement.offsetHeight)
    diffH = document.documentElement.offsetHeight;
    else if (document.body)
    diffH = document.body.offsetHeight;
    else
        diffH=0
    return diffH
    }var lastScrollY=0;
    function get_percent(){//获取浮动移动步幅
    var percent=.1*(get_diffY()-lastScrollY); 
    if(percent>0)percent=Math.ceil(percent); 
    else percent=Math.floor(percent); 
    return percent
    }function Float(){//窗口浮动
    var percent=get_percent();
    var obj=$("winpop");
    obj.style.top=parseInt(obj.offsetTop)+percent+"px";
    lastScrollY=lastScrollY+percent; 
    }window.onresize=function(){
    var obj=$("winpop");
    obj.style.top=get_diffH()+"px";
    lastScrollY=obj.offsetHeight+5; 
    }</script><body>
    <div id="winpop">
    <div class="title">您有新的消息<span class="close" onclick="hid_pop()">X</span></div>
        <div class="con">未读信息(1)</div>
    </div>
    <div style="height:1000px"></div>
    </body>
    </html>