spin.js似乎不起作用/出现

Aky*_*ian 2 html javascript css jquery spin.js

我正在尝试使用spin.js库来显示加载动画.但是,关闭spin.js开发人员示例我似乎无法让它工作/出现; 当我在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>
Run Code Online (Sandbox Code Playgroud)


感兴趣的人的工作代码(在同一目录中需要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>
Run Code Online (Sandbox Code Playgroud)

Emi*_*ily 8

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

<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>
Run Code Online (Sandbox Code Playgroud)