javascript - spin.js 似乎不工作/出现

标签 javascript jquery html css spin.js

我正在尝试使用 spin.js 库来显示加载动画。但是,关闭 spin.js developer example我似乎无法让它工作/出现;当我在 Firefox 中打开我的 html 文件时,空的 div 标签很明显。

这是我的代码 (spinnertest.html):

<html>
<head>
    <script src="spin.min.js">
        var opts = {
          lines: 13, // The number of lines to draw
          length: 7, // The length of each line
          width: 4, // The line thickness
          radius: 10, // The radius of the inner circle
          corners: 1, // Corner roundness (0..1)
          rotate: 0, // The rotation offset
          color: '#000', // #rgb or #rrggbb
          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("spinner");
        var spinner = new Spinner(opts).spin(target);
    </script>
</head>
<body>
    <div id="spinner">
    </div>
</body>


感兴趣者的工作代码(需要同一目录中的 jquery-1.9.0.min.js 和 spin.min.js):

<html>
<head>
    <script type="text/javascript" src="spin.min.js"></script>
    <script type="text/javascript" src="jquery-1.9.0.min.js"></script>
    <script type="text/javascript">
        $(function() {
            var opts = {
              lines: 13, // The number of lines to draw
              length: 7, // The length of each line
              width: 4, // The line thickness
              radius: 10, // The radius of the inner circle
              corners: 1, // Corner roundness (0..1)
              rotate: 0, // The rotation offset
              color: '#000', // #rgb or #rrggbb
              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("spinner");
            var spinner = new Spinner(opts).spin(target);
        });
    </script>
</head>
<body>
    <div id="spinner">
    </div>
</body>

最佳答案

我不相信带有 src 属性的 script 标签内的代码会执行。如果您将代码更改为以下内容,它是否有效?

<script type="text/javascript" src="spin.min.js"></script>
<script type="text/javascript">
  $(document).ready(function () {
    var opts = ...
    ...
    // all the code that you currently have between <script> and
    // </script> goes here
  });
</script>

关于javascript - spin.js 似乎不工作/出现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14677127/

相关文章:

javascript - 查找并替换数组中的匹配对象 - JavaScript

javascript - 使用多行时 Json 解析问题

javascript - Canvas JS 导致问题

javascript - 通过按空格键禁用滚动,然后如何在 textarea 和...中启用空格?

javascript - 每行选择仅触发一次 Kendo 网格更改事件

html - 垂直对齐图片和文字

javascript - 分离 Spring 和 Dojo 单页应用程序代码库

javascript - 如何将键值对象转换为对象数组

html - Bootstrap 4 将侧边栏折叠成导航栏下拉菜单

HTML 表格是隐藏的,不应该是