【问题标题】:spin.js not showing up on iPhone/iPadspin.js 没有出现在 iPhone/iPad 上
【发布时间】:2013-10-09 19:29:12
【问题描述】:

我使用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。

【问题讨论】:

    标签: html ios css css-position


    【解决方案1】:

    因为其他解决方案不起作用,而且我不会使用框架,所以我想出了一个 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();
    

    取自this post中的答案from Tony

    一个缺点:用户可以滚动离开微调器。你需要一些适应滚动的东西,例如显示在Fixed positioning in Mobile Safari

    【讨论】:

      猜你喜欢
      • 2016-02-04
      • 2011-05-01
      • 2013-10-10
      • 1970-01-01
      • 1970-01-01
      • 2012-08-21
      • 2013-08-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多