2016-04-26 85 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

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