[英]SVG & JavaScript - Animating SVG file object not working?
所以我有一個SVG文件。 如果你去網站它應該動畫它,但事實並非如此。 它在localhost中工作。 有人可以幫幫我嗎? 我覺得有些帖子已經在這里發過,但沒有人回答,所以我會做新的:)。
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);
}
我通過修復一些錯誤來實現它。
我必須定義這些未定義的變量:
var currentRotation = 0;
var beforeLoginSpinInterval;
var loggedinn;
你的setTimeout
缺少一個右大括號,所以我解決了這個問題。
這條線無效:
wheelSVG = $("object").contents().find("svg");
所以我把它推廣到:
wheelSVG = $("svg");
DEMO
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.