2014-10-16 49 views
1

我使用asp mvc,我需要使用spin.js,但不工作。這是我正在使用的代碼。錯誤,當我使用JavaScript的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); 

和消息是

「沒有定義微調」

任何想法我如何解決這個問題?

回答

0

嘗試使用絕對網址(使用http等方案)。

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

希望有幫助。

+0

我得到同樣的錯誤 「微調沒有定義」。 – Wilmer 2014-10-16 21:50:16

+0

我看到spin.min.js被正確下載,這個問題很奇怪,因爲我可以在互聯網上看到示例並且它們可以工作,但是當我將該代碼放到我的應用程序中時無法正常工作。 – Wilmer 2014-10-16 21:51:32

+0

@ user3303841然後您必須有其他問題。確切的代碼(在src中使用http)正在我的機器上運行。 – 40Alpha 2014-10-16 21:56:20

1

使用完全限定的旋轉庫路徑時,將其插入到StackOverflow代碼段(字面上複製您的問題,無需其他修改)時,它似乎工作正常。這可能意味着您的代碼可能存在其他問題(這是整個頁面),或者您的瀏覽器緩存了導致問題的某些內容。

<!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>

相關問題