2016-04-26 55 views
1

所以我有一個SVG文件。如果你去網站,它應該動畫,但它不會。它在localhost中工作。有人可以幫我嗎?我認爲已經有了一些帖子,但沒有人回答,所以我雖然會做出新的:)。SVG和JavaScript - 動畫SVG文件對象不起作用?

SVG文件:http://pastebin.com/raw/qn5gsTjV

JavaScript進行動感單車:

var wheelSVG = $(); 
var spinner = $(); 
$("object").load(function() { 
    wheelSVG = $("object").contents().find("svg"); 
    spinner = spinner.add(wheelSVG.find("#spin")); 
    center = wheelSVG.find("#ui ellipse"); 
    centerText = wheelSVG.find("#number"); 
    clearInterval(beforeLoginSpinInterval); 
    if (!loggedinn) { 
     beforeLoginSpinInterval = setInterval(function() { 
      currentRotation += 0.25; 
      spinner.css("transform", 'rotate(' + currentRotation + 'deg)'); 
     }, 20); 
    } 
}); 
setTimeout(function() { 
      wheelSVG = $("object").contents().find("svg"); 
      spinner = spinner.add(wheelSVG.find("#spin")); 
      center = wheelSVG.find("#ui ellipse"); 
      centerText = wheelSVG.find("#number"); 
      clearInterval(beforeLoginSpinInterval); 
      if (!loggedinn) { 
       beforeLoginSpinInterval = setInterval(function() { 
        currentRotation += 0.25; 
        spinner.css("transform", 'rotate(' + currentRotation + 'deg)'); 
       }, 10); 
      } 
+0

請創建一個[MCVE](http://stackoverflow.com/help/mcve),這樣我們就可以看到發生了什麼,而無需執行大量工作。 –

回答

0

我得到它通過固定了一些錯誤的工作。

我不得不定義這些不確定變量:

var currentRotation = 0; 
var beforeLoginSpinInterval; 
var loggedinn; 

setTimeout是缺少一個右括號,所以我固定的。

這條線不工作:

wheelSVG = $("object").contents().find("svg"); 

所以我把它概括爲:

wheelSVG = $("svg"); 

enter image description here

DEMO

SVG Spinning Wheel

+0

我會盡力的。謝謝,順便說一句。你能以某種方式看到JavaScript錯誤? –

+0

在Codepen中運行代碼時,我看到了使用Chrome開發人員工具控制檯的JavaScript錯誤。 –

+0

嗯:(,可惜我無法得到它在網站上工作:( –