2012年11月18日 星期日

jQuery Loading且置中

html部份
<div id="divLoading" style="background-color: Red; color: White; visibility: hidden; position: absolute; top: 0px; left: 0px; z-index:9999"> 資料傳輸中,請稍候... </div>
js部份
 <script type="text/javascript"> 
 $(function () { 
  var positionleft = $(window).width() / 2 - $("#divLoading").outerWidth(true) / 2; 
  var positiontop = $(window).height() / 2 - $("#divLoading").outerHeight(true) / 2;
  $("#divLoading").css("left", positionleft + "px").css("top",positiontop); //設定不Cache 
  $.ajaxSetup({ cache: false });
  $("#divLoading").ajaxSend(function () {
   $(this).css("visibility", "visible");  
  $.ajax({ type: 'post', url: 'Handler1.ashx',     
   data: { q: "" }, 
   success: function (result) { 
    $('#content').html(result); 
    $('#content').trigger("create"); 
  } }); 
 }); 
</script>