0

我使用spin.js在加载新页面时显示微调器。因为 IE 在动画 gif 方面存在问题,所以我使用了这个库。现在我发现它在iOS上不起作用。微调器根本没有出现。经测试:

  • 装有 iOS 6.1.3 的 iPhone
  • 装有 iOS 5.1.1 的 iPad

它适用于 Windows 的所有浏览器(甚至是 Windows 的 Safari)。

标题:

<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。

4

1 回答 1

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();

取自托尼这篇文章中的回答。

一个缺点:用户可以滚动离开微调器。您需要一些适应滚动的东西,例如Mobile Safari 中的 Fixed Positioning 中所示。

于 2013-10-03T07:49:45.807 回答