简体   繁体   English

NProgress带模态对话框以防止单击

[英]NProgress with modal dialog to prevent click

I am usign a app using NProgress.js. 我使用NProgress.js开发了一个应用程序。 Its amazing plugin. 其惊人的插件。

I whanto know it is possible to use with NProgress, a modal dialog ou something like it, to prevent click when NProgress is running in my $.ajax request. 我想知道可以在NProgress $ .ajax请求中运行NProgress时使用NProgress(一个类似它的模态对话框)来防止单击。

Tks TKS

This can be done, but the fading effect of the modal obscures the loading bar shown by NProgress. 可以这样做,但是模态的衰落效果使NProgress所示的加载条变得模糊。 So you may want to attach the loading bar to something other than the 'body' DOM element using something like 因此,您可能想使用以下方式将加载栏附加到“ body” DOM元素以外的其他内容上:

NProgress.configure({ parent: '#newContainer' });

In any case, simply drop a modal block somewhere in the body of the HTML page: 无论如何,只要在HTML页面的正文中的某个位置放置一个模式块即可:

<!-- Modal -->
<div class="modal fade" id="loadingModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h4 class="modal-title" id="myModalLabel">Fetching New Data</h4>
     </div>
   <div class="modal-body">
     Please wait...
  </div>
</div>

Initialize it in javascript (note that keyboard: false prevents typing from dismissing the modal, backdrop:static prevents clicking to dismiss): 用javascript初始化它(请注意,键盘:false阻止键入消除模式,而background:static阻止单击消除):

$('#loadingModal').modal({ show: false, keyboard: false, backdrop: 'static'});

Then show/hide it in an Ajax call appropriately: 然后在Ajax调用中适当地显示/隐藏它:

NProgress.start();
$('#loadingModal').modal('show');

$.ajax({...
  }).done(response => {
    // Handle success
  }).fail(err => {
    // Handle errors
  }).always(() => {
    $('#loadingModal').modal('hide');
    NProgress.done()
  });

I think this 我认为这

 NProgress.inc() 
 $.ajax({...})
  .done(function( data ) {
    ...
    NProgress.done()
  });

Remember that you must manage the errors. 请记住,您必须管理错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM