我正在尝试了解如何将setInterval与Paper.js一起使用。我做了一个简单的测试,在setInterval函数和外部使用相同的代码。它适用于后一种情况,但不适用于setInterval内部。有什么想法吗?
// interval (not working)//
var id = setInterval(function() {
var path = new Path.Circle(new Point(20, 20), 30);
path.fillColor = 'red';
var pointX = 80;
var pointY = 50;
var symbol = new Symbol(path);
symbol.place(new Point(pointX, pointY));
pointX = pointX+50;
pointY = pointY+50;
}
}, 1000);
//no interval//
var path = new Path.Circle(new Point(20, 20), 30);
path.fillColor = 'red';
var pointX = 80;
var pointY = 50;
var symbol = new Symbol(path);
symbol.place(new Point(pointX, pointY));
pointX = pointX+50;
pointY = pointY+50;
symbol.place(new Point(pointX, pointY));
http://jsfiddle.net/miguelrivero/2BzUL/10/
谢谢!
答案 0 :(得分:1)
第一个原因是你有额外的}
,这是一个语法错误。第二个原因[s]是错误:
Refused to execute script from 'https://raw.github.com/paperjs/paper.js/master/dist/paper.js' because its MIME type ('text/plain') is not executable, and strict MIME type checking is enabled. fiddle.jshell.net/miguelrivero/2BzUL/10/show/:1
Uncaught SyntaxError: Unexpected token } fiddle.jshell.net/miguelrivero/2BzUL/10/show/:40
Refused to execute script from 'https://raw.github.com/paperjs/paper.js/master/dist/paper.js' because its MIME type ('text/plain') is not executable, and strict MIME type checking is enabled. fiddle.jshell.net/_display/:1
Uncaught SyntaxError: Unexpected token } fiddle.jshell.net/_display/:40
Refused to execute script from 'https://raw.github.com/paperjs/paper.js/master/dist/paper.js' because its MIME type ('text/plain') is not executable, and strict MIME type checking is enabled. fiddle.jshell.net/_display/:1
Uncaught ReferenceError: Path is not defined fiddle.jshell.net/_display/:29
Uncaught ReferenceError: Path is not defined