自己写的一个小插件,还有很多需要完善。。。

(function ($) {
    $.fn.StartLoading = function (option) {
        var defaultVal = {
            loadgif: 'image/loading.gif',
            backcolor: 'white',
            picheight: 50,
            picwidth: 50,
            fullshowpic: false,//图片是否设置透明度
            opacity: 0.5,
            timeout: 3000
        }
        var result = $.extend({}, defaultVal, option);
        var $obj = $(this);//选择器的Jquery对象
        var iswndordoc = false;
        if ($(this).get(0) == document || $(this).get(0) == window || $(this).get(0) == document.body) {
            iswndordoc = true;
            $obj = $(document.body);
        }
        //获取对象属性
        var constClone = {
            constwidth: $obj.width(),
            constheight: $obj.height(),
            constleft: iswndordoc == true ? 0 : $obj.offset().left,
            consttop: iswndordoc == true ? 0 : $obj.offset().top
        }
        if (iswndordoc) {
            var $clonebottom = $("<div></div>");
        } else {
            if ($(this)[0].tagName != "div") {
                var $objTemp = $("<div id=\"_temp_div\" style=\"width:" + constClone.constwidth + "; height:" + constClone.constheight + "; left:" + constClone.constleft + "; top:" + constClone.consttop + "\"></div>");
                $($obj.parent().get(0)).append($objTemp);
                $obj = $objTemp;
            }
            //生成最底层DIV
            var $clonebottom = $obj.clone().removeAttr("id").removeAttr("class").removeAttr("name");
        }

//设置最底层DIV属性
        $clonebottom.removeClass().removeAttr("style").empty().css({
            "position": "absolute",
            "left": constClone.constleft,
            "top": constClone.consttop,
            "z_index": "10000",
            "width": constClone.constwidth,
            "height": constClone.constheight,
            "background-color": "transparent"
        });
        var $cloneTop = $clonebottom.clone().css({ "z_index": "9999", "background-color": "" + result.backcolor + "", "position": "" });
        $clonebottom.append($cloneTop);
        $clonebottom.append("<img id=\"_loading_plugin\" src=\"" + result.loadgif + "\" style=\"position:absolute;z_index: 9999\"/>");
        if (iswndordoc) {
            $obj.append($clonebottom);
        } else {
            $($obj.parent().get(0)).append($clonebottom);
        }
        var $imgloading = $("#_loading_plugin");
        $imgloading.css({ "width": "" + result.picwidth + "px", "height": "" + result.picheight + "px" });
        $imgloading.css({ "left": (constClone.constwidth - $imgloading.width()) / 2, "top": (constClone.constheight - $imgloading.height()) / 2 });
        if (result.fullshowpic)
            $clonebottom.css("opacity", "" + result.opacity + "");
        else
            $cloneTop.css("opacity", "" + result.opacity + "");
        var hand = setTimeout(function () {
            $clonebottom.fadeOut("slow", function () {
                $(this).remove();
                clearTimeout(hand);
            });
        }, result.timeout)
        return $clonebottom;
    }

$.fn.StopLoading = function () {
        var $globalthis = $(this);
        $globalthis.remove()
    }
})(jQuery)

用法: 开始显示  var $load = $(window).StartLoading({ timeout: 1000000, fullshowpic: true }); 结束显示:  $load.StopLoading();

加载等待loading的更多相关文章

  1. [Swift通天遁地]一、超级工具-(11)使用EZLoadingActivity制作Loading加载等待动画

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  2. vue-element-admin 全局loading加载等待

    最近遇到需求: 全局加载loading,所有接口都要可以手动控制是否展示加载等待的功能 当拿到这个需求的时候我是拒绝的,因为我以及局部写好了0.0,这是要大改呀....,没办法老板的要求,只能硬着头皮 ...

  3. 《动手实现一个网页加载进度loading》

    loading随处可见,比如一个app经常会有下拉刷新,上拉加载的功能,在刷新和加载的过程中为了让用户感知到 load 的过程,我们会使用一些过渡动画来表达.最常见的比如"转圈圈" ...

  4. IOS开发UI篇之──自定义加载等待框(MBProgressHUD)

    本文转载至 http://blog.csdn.net/xunyn/article/details/8064984   原文地址http://www.189works.com/article-89289 ...

  5. WPF加载等待动画

    原文:WPF加载等待动画 原文地址:https://www.codeproject.com/Articles/57984/WPF-Loading-Wait-Adorner 界面遮罩 <UserC ...

  6. fakeLoader页面加载前loading演示8种效果

    提高用户体验的插件fakeLoader页面加载前loading演示8种效果 在线预览 下载地址 示例代码 <div id="main"> <div class=& ...

  7. C#窗体的加载等待(BackgroundWorker控件)实现

    窗体拉一个Button按钮和一个加载等待显示的label, label默认隐藏,点击按钮时显示这个label,加载完再隐藏 1.工具箱拉BackgroundWorker控件到窗体 2.backgrou ...

  8. cocos2d-x游戏开发(十五)游戏加载动画loading界面

    个人原创,欢迎转载:http://blog.csdn.net/dawn_moon/article/details/11478885 这个资源加载的loading界面demo是在玩客网做逆转三国的时候随 ...

  9. ajax加载菊花loading效果

    Ajax异步请求的时候,一般都会利用一个动态的gif小图片来制作一个Ajax Loading,以便增加用户体验. 这里我们可以使用Spin.js,该js脚本压缩后5k,可以不用任何图片,任何外部CSS ...

随机推荐

  1. iOS UI01_UIView

    // //  AppDelegate.m //  UI01_UIView // //  Created by dllo on 15/7/29. //  Copyright (c) 2015年 zhoz ...

  2. UVA 11077 Find the Permutations 递推置换

                               Find the Permutations Sorting is one of the most used operations in real ...

  3. Linux基础03

    ** Linux基本操作常用命令(三) ** Linux的软件包 Linux的软件把分为“源码包”和“二进制包” 源码包:免费,开源 二进制包:系统默认包,即RPM包(上一节我们通过rpm卸载过ope ...

  4. Kafka Consumer2

    本文记录了和conumser相关的几个类. 首先是RequestFuture这个类,consumer和服务端通信使用它作为返回值. 其次是HeartBeat机制,consumer和coordinato ...

  5. (转载)PopuWindow和软键盘共存时的设置

    PopuWindow和软键盘共存时的设置 收藏 artshell 发表于 2年前 阅读 1499 收藏 10 点赞 2 评论 0 腾讯云上实验室 1小时搭建人工智能应用 让技术更容易入门>> ...

  6. HDU 5234 Happy birthday【DP】

    题意:给出n*m的格子,每个格子的值为w[i][j],在值不超过k的时候,可以往右或者往下走,问从(1,1)走到(n,m)能够得到的最大的值 类似于背包 d[i][j][k]=maxx(d[i-1][ ...

  7. windows 路由

    route ? 查看帮助 route print 查看路由表 添加一条路由: route add 10.10.10.0 mask 255.255.255.0  192.168.1.1 #到达10.10 ...

  8. webkit Safari的样式库

    1,webkit Box模型 CSS定义:-webkit-border-bottom-left-radius: radius; CSS定义:-webkit-border-top-left-radius ...

  9. 使用IDEA在Maven中创建MyBatis逆向工程以及需要注意的问题(入门)

    逆向工程简介: mybatis官方提供逆向工程,可以针对单表自动生成mybatis执行所需要的代码(mapper.java.mapper.xml.pojo…),可以让程序员将更多的精力放在繁杂的业务逻 ...

  10. js 监听ios手机键盘弹起和收起的事件

    document.body.addEventListener('focusin', () => { //软键盘弹起事件 console.log("键盘弹起") }) docu ...