右下角滑出視窗 sheyMsg

來源:互聯網
上載者:User

/* 
 *Author:sohighthesky 
 *From:http://blog.csdn.net/sohighthesky   
 *Date:2009-11-9 
 */ 
/* 
 *box 指定要顯示訊息框或者其id 
 *options:參見代碼中setOptions中的注釋 
 */ 
var sheyMsg=function(box,options) {  
    this.box=this.g(box);  
    this.setOptions(options);  
    this.init();  
}  
sheyMsg.prototype={  
    ae:function(e,call) {  
        if(window.addEventListener)window.addEventListener(e,call,false);  
        else window.attachEvent("on"+e,call);  
    },  
    g:function(id) {return typeof(id)=="string"?document.getElementById(id):id; },  
    isFixed:!window.ActiveXObject || (navigator.userAgent.indexOf("MSIE 6")==-1 &&  document.compatMode=="CSS1Compat"),  
    setOptions:function(options) {  
        this.options={//預設配置  
                showDelay:10,//顯示延時  
                autoHide:30,//自動隱藏時間,設定為0時,不自動隱藏  
                onShow:function(){},//顯示後調用  
                onHide:function(){}//隱藏後調用  
        };  
        for(var o in options) {  
            this.options[o]=options[o];  
        }  
    },  
    hide:function() {//隱藏  
        var _top=this.box.clientHeight;  
        var o=this;  
        if(/ing$/.test(o.status))return;  
        o.status="hiding";  
        clearTimeout(o.tt);  
        o.t=setInterval(function() {  
            if(o.isFixed)  
                o.box.style.bottom=(-o.box.clientHeight+(--_top))+'px';  
            else 
                o.box.style.top=o.de.scrollTop+o.de.clientHeight-5-(--_top) +"px";  
            if(_top==-5) {  
                clearInterval(o.t);  
                o.status="hide";  
                o.box.style.display="none";  
                o.options.onHide();  
            }  
        },5);  
    },  
    show:function() {//顯示  
        var _top=0;  
        var o=this;  
        if(/ing$/.test(o.status))return;  
        o.status="showing";  
        clearTimeout(o.tt);  
        o.box.style.display="block";  
        o.t=setInterval(function() {  
            if(o.isFixed)  
                o.box.style.bottom=(-o.box.clientHeight+(++_top))+"px";  
            else 
                o.box.style.top=(o.de.scrollTop+o.de.clientHeight-5-(++_top)) +"px";  
            if(_top==o.box.clientHeight) {  
                clearInterval(o.t);  
                o.status="show";  
                o.options.onShow();  
                var h=o.options.autoHide-0;  
                if(h) o.tt=setTimeout(function() {o.hide();},h*1000);  
            }  
        },1);  
    },  
    fixIE6:function() {//IE6 滾動定位  
        this.box.style.left=this.de.scrollLeft+this.de.clientWidth-this.box.clientWidth-2+"px";  
        if(this.status=="show") {              
            this.box.style.top=this.de.scrollTop+this.de.clientHeight-this.box.clientHeight-5+"px";  
        } else if(this.status=="hide") {  
            this.box.style.top=this.de.scrollTop+this.de.clientHeight+5+"px";  
        }  
    },  
    init:function() {  
        with(this.box.style) {  
            display="block";//顯示之後才能取出寬度和高度  
            if(this.isFixed) {  
                position="fixed";  
                right="2px";  
                bottom=(-this.box.clientHeight-5)+"px";  
            } else {  
                position="absolute";  
            }  
        }  
        this.status="hide";  
        var o=this;  
        if(!this.isFixed) {  
            o.de=document.compatMode=="CSS1Compat"?document.documentElement:document.body;  
            var timer;  
            this.ae("resize",function() { clearTimeout(timer);timer=setTimeout(function(){o.fixIE6.call(o)},30);});  
            this.ae("scroll",function() { clearTimeout(timer);timer=setTimeout(function(){o.fixIE6.call(o)},30);});  
            this.fixIE6();//載入時指定位置  
        }  
        o.box.style.display="none";  
        o.tt=setTimeout(function() {o.show();},o.options.showDelay*1000);  
    }  

本文來自CSDN部落格,轉載請標明出處:http://blog.csdn.net/sohighthesky/archive/2009/11/10/4795886.aspx

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.