我使用javascript spin.js库时出错

时间:2014-10-16 21:36:44

标签: javascript asp.net-mvc

我正在使用asp mvc,我需要使用spin.js但是不能正常工作。这是我正在使用的代码。

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>spin.js example</title>
    <script src="//cdnjs.cloudflare.com/ajax/libs/spin.js/1.2.7/spin.min.js"></script>
</head>
<body>
    <div id="foo"></div>
    <script>
        var opts = {
            lines: 10, // 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: 25, // Top position relative to parent in px
            left: 25 // Left position relative to parent in px
        };
        var target = document.getElementById('foo');
        var spinner = new Spinner(opts).spin(target);
    </script>
</body>
</html>

但是当我运行它时,此行显示异常

var spinner = new Spinner(opts).spin(target);

,消息是

  

&#34; Spinner未定义&#34;

关于我如何解决这个问题的任何想法?

2 个答案:

答案 0 :(得分:2)

使用自旋库的完全限定路径,在插入StackOverflow代码片段时,它似乎工作正常(字面上复制了您的问题,没有其他修改)。这可能会指出您的代码可能存在其他问题(这是整个页面)还是您的浏览器缓存了导致问题的问题。

&#13;
&#13;
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>spin.js example</title>
    <script src="http://cdnjs.cloudflare.com/ajax/libs/spin.js/1.2.7/spin.min.js"></script>
</head>
<body>
    <div id="foo"></div>
    <script>
        var opts = {
            lines: 10, // 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: 25, // Top position relative to parent in px
            left: 25 // Left position relative to parent in px
        };
        var target = document.getElementById('foo');
        var spinner = new Spinner(opts).spin(target);
    </script>
</body>
</html>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

尝试使用绝对网址(使用类似http的方案)。

<script src="http://cdnjs.cloudflare.com/ajax/libs/spin.js/1.2.7/spin.min.js"/>

希望这有帮助。