dpiz9879 2015-09-05 13:05
浏览 33

jquery在处理时显示微调器

When '.btn-save' is clicked, a server side script(probably php) would connect with the server to upload image or form data to the server. While this process is happening I want a spinner to show.

My HTML for the spinner is:

<div class="spinner">
   <img src="img/loader.gif" alt="Processing" />
</div>

My CSS:

.spinner {
    z-index: 9999;
    position: fixed;
    background: rgba(0, 0, 0, 0.1);
    width: 100%;
    height: 100%;
    top: 0; left: 0; right: 0; bottom: 0;
    display: none;
}
.spinner img {
    position: fixed;
    left: 50%;
    top: 50%;
    z-index: 10000;
}

I found an answer that suggested doing something like this:

        $body = $("body");

        $(document).on({
            ajaxStart: function() { $body.addClass("loading");    },
             ajaxStop: function() { $body.removeClass("loading"); }    
        });

The CSS:

body.loading {
    overflow: hidden;   
}

body.loading .spinner {
    display: block;
}

I want to know if this will work for me or if you could suggest something different in my case.

  • 写回答

3条回答 默认 最新

  • douzuo0711 2015-09-05 13:23
    关注

    I done similar thing ,

    <form id="feedback">
    <div class="spinner" id="loader_login" style="display: none;">
    <input type="submit" value="submit" >
    

    In your jquery after button click,

    $('#feedback').submit(function (event) {
            $("#loader_login").css("display", "block");
    
           //data process
    
           $("#loader_login").css("display", "none");
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?