作为程序员一定要保持良好的睡眠,才能好编程

javascript扩展库

发布时间:2017-03-14

//QQ咨询
(function (){
    zns.site.common=zns.site.common||{};
    zns.site.common.create=function ()
    {
        var buffer=zns.site.fx.buffer;
        var flex=zns.site.fx.flex;
        //微信弹出层
        var oDivWX=document.createElement('div');
        oDivWX.className='weixinShow';
        oDivWX.innerHTML=
            '<img src="'+_g_path+'images/weixin.jpg" alt="智能社官方微信"><span></span>'+
            '<a href="javascript:;" class="btn_close"></a>';
        document.body.appendChild(oDivWX);
        //点击弹出微信弹出层
        var time_wx=setInterval(function (){
            var oDivSlide=getEle('.newOnline')[0];
            if(!oDivSlide)return;
            var oBtn=getEle('.c_weixin', oDivSlide)[0];
            if(!oBtn)return;
            oBtn.onclick=function ()
            {
                oDivWX.style.display='block';
                oDivWX.style.top='-100%';
                flex(oDivWX, {top: -100}, {top: 0}, function (now){
                    oDivWX.style.top=now.top+'%';
                }, null, 4, 0.6);
            };
            getEle('.btn_close', oDivWX)[0].onclick=function ()
            {
                buffer(oDivWX, {top: 0}, {top: 100}, function (now){
                    oDivWX.style.top=now.top+'%';
                }, function (){
                    oDivWX.style.display='none';
                });
            };
            clearInterval(time_wx);
        }, 10);
        //shadow_bg
        (function (){
            var oDiv=document.createElement('div');
            oDiv.className='shadow_bg';
            oDiv.innerHTML='<img src="'+_g_path+'images/login_layerBg.png" alt="" />';
            document.body.appendChild(oDiv);
        })();
        //gotoTop
        (function (){
            var oBtn=document.createElement('a');
            var alpha=0;
            oBtn.href='javascript:;';
            oBtn.className='gotoTop';
            oBtn.style.display='none';
            document.body.appendChild(oBtn);
            //滚动的时候出现
            function rePos()
            {
                var scrollTop=document.documentElement.scrollTop||document.body.scrollTop;
                oBtn.style.display='block';
                if(scrollTop)
                {
                    buffer(oBtn, {opacity: alpha}, {opacity: 100}, function (now){
                        alpha=now.opacity;
                        this.style.filter='alpha(opacity:'+now.opacity+')';
                        this.style.opacity=now.opacity/100;
                    });
                }
                else
                {
                    buffer(oBtn, {opacity: alpha}, {opacity: 0}, function (now){
                        alpha=now.opacity;
                        this.style.filter='alpha(opacity:'+now.opacity+')';
                        this.style.opacity=now.opacity/100;
                    }, function (){
                        oBtn.style.display='none';
                    });
                }
            }
            bindEvent(window, 'scroll', rePos);
            //bindEvent(window, 'resize', rePos);
            //点击回到顶部
            oBtn.onclick=function ()
            {
                zns_scroll_to(0);
            };
        })();
    };
})();
function zns_scroll_to(n, fnEnd)
{
    var timer=null;
    var bySys=true;
    bindEvent(window, 'scroll', fn);
    function fn()
    {
        var scrollTop=document.documentElement.scrollTop||document.body.scrollTop;
        if(!bySys)
        {
            clearInterval(timer);
            if(fnEnd)fnEnd(false);
            unbindEvent(window, 'scroll', fn);
        }
        bySys=false;
    }
    timer=setInterval(function (){
        var scrollTop=document.documentElement.scrollTop||document.body.scrollTop;
        var speed=(n-scrollTop)/4;
        speed=speed>0?Math.ceil(speed):Math.floor(speed);
        scrollTop+=speed;
        bySys=true;
        document.documentElement.scrollTop=scrollTop;
        document.body.scrollTop=scrollTop;
        if(scrollTop==n)
        {
            clearInterval(timer);
            if(fnEnd)fnEnd(true);
            unbindEvent(window, 'scroll', fn);
        }
    }, 30);
}
function alert_sm(msg, bOk, iShow, iHide)
{
    if(zns.site.fx.browser_test.IE6)
    {
        alert(msg);
        return;
    }
    var linear=zns.site.fx.linear;
    if(bOk==undefined)bOk=true;
    if(iShow==undefined)iShow=0;
    if(iHide==undefined)iHide=3500;
    var oDiv=document.createElement('div');
    oDiv.className='info';
    oDiv.innerHTML=
        '<div class="info_c">'+
            '<span class="'+(bOk?'correct':'error')+'"></span><em>'+msg+'</em>'+
        '</div>'+
        '<div class="info_r"></div>';
    document.body.appendChild(oDiv);
    if(navigator.userAgent.indexOf('MSIE 6')!=-1)
    {
        var scrollLeft=document.documentElement.scrollLeft||document.body.scrollLeft;
        var scrollTop=document.documentElement.scrollTop||document.body.scrollTop;
        oDiv.style.display='block';
        oDiv.style.left=scrollLeft+(document.documentElement.clientWidth-oDiv.offsetWidth)/2+'px';
        oDiv.style.top=scrollTop+(document.documentElement.clientHeight-oDiv.offsetHeight)/2+'px';
        oDiv.style.display='none';
    }
    else
    {
        oDiv.style.display='block';
        oDiv.style.left=(document.documentElement.clientWidth-oDiv.offsetWidth)/2+'px';
        oDiv.style.top=(document.documentElement.clientHeight-oDiv.offsetHeight)/2+'px';
        oDiv.style.display='none';
    }
    setTimeout(function (){
        oDiv.style.filter='alpha(opacity:0)';
        oDiv.style.opacity='0';
        oDiv.style.display='block';
        linear(oDiv, {opacity:0}, {opacity:100}, function (now){
            oDiv.style.filter='alpha(opacity:'+now.opacity+')';
            oDiv.style.opacity=now.opacity/100;
        }, function (){
            setTimeout(function (){
                linear(oDiv, {opacity:100}, {opacity:0}, function (now){
                    oDiv.style.filter='alpha(opacity:'+now.opacity+')';
                    oDiv.style.opacity=now.opacity/100;
                }, function (){
                    document.body.removeChild(oDiv);
                }, 10);
            }, iHide);
        }, 10);
    }, iShow);
}