js公共弹出窗插件

/*错误提示框*/
var wr = function() {
    var wrap = '<div class="wrapBox opacity">&nbsp;</div>';
    var callback;
    var me = this;
    var htmlBox = '<div class="alertBox opacity"></div>';
    // 遮罩显示
    me.faIn = function faIn(callback) {
        $('body').append(wrap);
        $(wrap).fadeIn(150, function() {
            $('.bodyBox').addClass('overAuto');
            if (callback) {
                callback();
            }
            ;
        });
    };
    // 遮罩隐藏
    me.faOut = function(callback) {
        $('.wrapBox').fadeOut(150, function() {
            $('.bodyBox').removeClass('overAuto');
            if (callback) {
                callback();
            }
            ;
            $(this).remove();
        });
    };
    // 公共提示框
    me.alert = function(message, callback) {
        if(message){
            var pHtml = '<p>' + message + '</p>';
            var inhtml = $(htmlBox).append(pHtml);
            $('body').append(inhtml);
            $(inhtml).fadeIn(250, function() {
                setTimeout(function() {
                    $(inhtml).fadeOut(150, function() {
                        $(this).html('');
                        $(this).remove();
                    });
                    if (callback) {
                        callback();
                    }
                }, 2000);
            });
        }

    };

    me.alertHide=function(){
        $('body').find('.alertBox').fadeOut(0,function(){
            $(this).html('');
            $(this).remove();
        });
    };

    // 电话
    me.tel = function(tel, callback) {
        var tel = '<p class="telBox"><a href="tel:' + tel + '">' + tel
            + '</a></p>';
        if (callback) {
            callback();
        }
        $('body').append(htmlBox);
        $('body').append(tel);
        $(htmlBox).fadeIn(250);
        $('.alertBox').click(function() {
            $('.telBox').fadeOut(150, function() {
                $(this).remove();
            });
            $(this).fadeOut(0, function() {
                $(this).html('');
                $(this).remove();

            });
        });
    };
};
var wrap = new wr();

 

posted @ 2018-03-02 10:56  故事里的牧羊人  阅读(243)  评论(0编辑  收藏  举报