[英]spin.js doesn't seem to work/ appear
I'm attempting to use the spin.js library to display a loading animation. 我正在尝试使用spin.js库显示加载动画。 However, going off the spin.js developer example I can't seem to get it to work/ appear;
但是,关闭spin.js开发人员示例后,我似乎无法使其正常运行/显示; this is apparent by the empty div tag when I open my html file in Firefox.
当我在Firefox中打开html文件时,通过空div标签可以明显看出这一点。
Here is my code (spinnertest.html): 这是我的代码(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>
Working code for those interested (requires jquery-1.9.0.min.js and spin.min.js in the same directory): 感兴趣的人的工作代码(在同一目录中需要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>
I don't believe that code inside a script
tag with a src attribute will execute. 我不相信带有src属性的
script
标记内的代码会执行。 If you change your code to the following, does it work? 如果将代码更改为以下代码,是否可以使用?
<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>
You have to initialize it in a DOM ready state, otherwise target
will be null
. 您必须在DOM就绪状态下初始化它,否则
target
将为null
。 You should also have the include script in a separate script
tag. 您还应该在单独的
script
标记中包含include脚本。
Using jquery... 使用jQuery ...
$(function() {
var target = document.getElementById("spinner");
var spinner = new Spinner(opts).spin(target);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.