2012-02-16 102 views
0

我想添加一個進度動畫到一個函數,以便它顯示在函數的開頭,然後消失在它的結尾。JQuery函數添加進度動畫

喜歡的東西:

<script type="text/javascript"> 
function myfunction() { 
    //Display progress animation here 
    $('input[type=submit]#submit').click(); 
    etc... 
    //Hide the progress animation here 
} 
?> 

UPDATE:

這是我目前的Ajax代碼:

<script type="text/javascript"> 
function myfunction() { 
    $("#ajax-form").submit(function(){ 
     $.post("submit.php", 
     $("#ajax-form").serialize(), 
      function(data){ 
      mysubmitForm(); 

      } 

     ); 
     return false; 

    }); 
} 
</script> 
+1

[.show()](http://docs.jquery.com/Show)和[ .hide()](http://docs.jquery.com/Hide)。 – JJJ 2012-02-16 14:54:26

+0

即將發生的事情 - 你打算去檢索一些數據嗎?我們需要更多的信息 – MMM 2012-02-16 14:55:09

+0

上面添加的代碼 – Satch3000 2012-02-16 15:28:08

回答

1

什麼埃尼斯說:

<div class="loader">Loading...</div> 

<script type="text/javascript"> 

$(function(){ 

    $.ajax({ 
     url: 'the url', 
     data: {}, 
     success: function() { 
      $('.loader').fadeOut(); 
     } 
    }); 
}); 

</script> 

更新:

<script type="text/javascript"> 

function myfunction() { 

$("#ajax-form").submit(function(){ 
    //show loader here 
    $.post("submit.php", $("#ajax-form").serialize(), 
     function(data){ 
      mysubmitForm(); 
      //and hide it here 
     } 

    ); 
    return false; 

}); 

}

+0

我的Ajax代碼有點不同...我已經添加了代碼...代碼您指導我在上面的代碼中添加加載程序代碼的位置? – Satch3000 2012-02-16 15:27:42

+0

@ Satch3000更新了答案 – Johan 2012-02-16 15:34:45

1

如果你正在使用類似$。阿賈克斯(),那麼你可以有一個格與進步圖像可見befor阿賈克斯調用,並使阿賈克斯成功事件無形呼叫