2013-10-03 152 views
0

我使用spin.js顯示加載新頁面時的微調。因爲IE瀏覽器在動畫gif時遇到了問題,所以我使用這個庫。現在我發現它不適用於iOS。微調根本沒有出現。測試了:spin.js沒有顯示在iPhone/iPad上

  • iPhone與iOS 6.1.3
  • 的iPad與iOS 5.1.1

它正在每一個瀏覽器的Windows(甚至Safari瀏覽器適用於Windows)。

部首:

<script type="text/javascript" src="../js/spin.min.js"></script> 

閉體之前:

<div id ="center" style="position:fixed;top:50%;left:50%"></div> 
<script> 
    var opts = { 
     lines: 13, // The number of lines to draw 
     length: 8, // The length of each line 
     width: 4, // The line thickness 
     radius: 11, // The radius of the inner circle 
     corners: 1, // Corner roundness (0..1) 
     rotate: 0, // The rotation offset 
     direction: 1, // 1: clockwise, -1: counterclockwise 
     color: '#000', // #rgb or #rrggbb or array of colors 
     speed: 1, // Rounds per second 
     trail: 60, // Afterglow percentage 
     shadow: false, // Whether to render a shadow 
     hwaccel: false, // Whether to use hardware acceleration 
     className: 'spinner', // The CSS class to assign to the spinner 
     zIndex: 2e9, // The z-index (defaults to 2000000000) 
     top: 'auto', // Top position relative to parent in px 
     left: 'auto' // Left position relative to parent in px 
    }; 
    var target = document.getElementById('center'); 
    var spinner = new Spinner(opts); 

    $("#select-place input").click(function(){ 
     spinner.spin(target); 
    }); 
    $(window).bind("load", function() { 
     spinner.stop(); 
    }); 
</script> 

我試圖用另一種元素。它在這裏起作用。問題是position:fixed。我讀到iOS 5支持這一點。即使在iOS上,如何將微調器居中在屏幕中間?該頁面不是針對移動設備明確構建的。它主要是桌面版本,但它也適用於iOS。

回答

0

由於其他解決方案沒有奏效,我不會使用框架,所以我想出了一個JS解決方案。簡單地計算出屏幕中間用JS:

jQuery.fn.center = function() { 
    this.css("position","absolute"); 
    this.css("top", Math.max(0, (($(window).height() - $(this).outerHeight())/2) + 
               $(window).scrollTop()) + "px"); 
    this.css("left", Math.max(0, (($(window).width() - $(this).outerWidth())/2) + 
               $(window).scrollLeft()) + "px"); 
    return this; 
} 

$('#center').center(); 

從答案from Tonythis post服用。

一個缺點:用戶可以從微調器滾動。您需要一些適合滾動的內容,例如如Fixed positioning in Mobile Safari所示。