JS(二十四)遮盖层

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u014744118/article/details/78886565
(function (a) {
    "use strict";
    if ("function" === typeof define && define.amd)
        define(["jquery"], a);
    else if ("object" === typeof exports)
        module.exports = a(require("jquery"));
    else {
        if ("undefined" === typeof jQuery) throw "Dropdown requires jQuery to be loaded first";
        a(jQuery);
    }
})(function ($) {
    $.fn.cloak = function (text) {
        var divCloak = $('<div class="jq-cloak-main">' +
            '<div class="jq-cloak-content">' + (text ? text : 'Loading...') + '</div>' +
            '</div>');

        $(this).prepend(divCloak);
        if ($(this).get(0).tagName !== 'BODY'){
            divCloak.width($(this).outerWidth());
            divCloak.height($(this).outerHeight());
            divCloak.css('margin-left', '-' + $(this).css('padding-left'));
            divCloak.css('margin-top', '-' + $(this).css('padding-top'));
        }
        else{
            divCloak.width('100%');
            divCloak.height('100%');
        }


        divCloak.find('.jq-cloak-content').css('margin-left', -divCloak.find('.jq-cloak-content').width() / 2);
    };

    $.fn.uncloak = function () {
        $('div.jq-cloak-main').remove();
    };
});

添加和去掉遮盖:

$('body').cloak('<i class="fa fa-spinner fa-spin mr-10"></i>玩命加载中...');
$('body').uncloak();



猜你喜欢

转载自blog.csdn.net/u014744118/article/details/78886565