使用 Raphael JS 在屏幕上浮动形状
我正在努力让一些形状随机漂浮在屏幕上。最终它们将相互交互,并具有 onclick 函数。我可以让圆圈在屏幕上渲染,但无法让它们运动。看来 .animate() 函数不是我这里需要的。
有谁知道我会怎么做?
这是我所拥有的:
jQuery(function ($) {
// Global Vars
var items = 30,
width = window.innerWidth,
height = window.innerHeight,
paper = Raphael("galaxy", width, height),
frameRate = 100,
i,
galaxy = [],
star = [],
stars = [];
// Do some variants for each item
for (i = 0; i<items; i++ ) {
stars[i] = {
x : Math.random() * width,
y : Math.random() * height,
r : Math.random()*255,
g : Math.random()*255,
b : Math.random()*255,
size : Math.random() * 20
}
}
// Creates canvas 320 × 200 at 10, 50
// Creates circle at x = 50, y = 40, with radius 10
for (i = 0; i<items; i++ ) {
star[i] = paper.circle(stars[i].x, stars[i].y, stars[i].size);
star[i].attr("fill", "rgb("+stars[i].r+", "+stars[i].g+", "+stars[i].b+")");
star[i].attr("stroke", "none");
}//end for
});
I am working on having some shapes floating around the screen at random. Eventually they will interact with each other, as well as have onclick functions. I can get the circles to render on screen, but I cannot get them to have motion. It seems that the .animate() function is not what I need here.
Does anyone know how I would go about this?
Here is what I have:
jQuery(function ($) {
// Global Vars
var items = 30,
width = window.innerWidth,
height = window.innerHeight,
paper = Raphael("galaxy", width, height),
frameRate = 100,
i,
galaxy = [],
star = [],
stars = [];
// Do some variants for each item
for (i = 0; i<items; i++ ) {
stars[i] = {
x : Math.random() * width,
y : Math.random() * height,
r : Math.random()*255,
g : Math.random()*255,
b : Math.random()*255,
size : Math.random() * 20
}
}
// Creates canvas 320 × 200 at 10, 50
// Creates circle at x = 50, y = 40, with radius 10
for (i = 0; i<items; i++ ) {
star[i] = paper.circle(stars[i].x, stars[i].y, stars[i].size);
star[i].attr("fill", "rgb("+stars[i].r+", "+stars[i].g+", "+stars[i].b+")");
star[i].attr("stroke", "none");
}//end for
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它可以与 animate() 一起使用。例如,如果您将其添加到上述函数中:
您的圆圈会飞来飞去。当然,要让它们真正漂浮甚至互动还有很长的路要走,但这也许是一个起点。
it could work with animate(). If you e.g. add this to the above function:
your circles fly around. Of course it's still a long way to go to have them really floating or even interaction, but it's maybe a starting point.