我是拉斐尔的新手,我真的被卡住了,我想用拉斐尔旋转一个div及其内容,使用一个按钮.
理想情况下,我希望在单击按钮时有一个从0度到-90度的平滑动画,然后再次单击该按钮时,动画将反转.我想我会在鼠标单击时更改id或类,以便我可以对两个动画使用相同的按钮.这是明智的吗?
我真的希望得到一些帮助,我的Sandbox位于http://jsbin.com/isijo/,您可以在http://jsbin.com/isijo/edit上进行编辑
非常感谢您的帮助.
您好,欢迎来到拉斐尔!
我已经看了Raphael超过几个月,虽然文档不是很全面,但软件很棒.
我一直在以多种方式将Divs与Raphael对象混合在一起,对于哪些有效,哪些无效有一种"感觉".
我建议你不要尝试旋转div,而是(而不是)Raphael对象.
首先,您可以使用下面的"可调整"代码制作一套闪亮的拉斐尔按钮.
var bcontrols = new Array();
var yheight = 300;
for (var i = 0; i < 3; i++) {
bcontrols[i] = paper.circle(15 + (35 * i), yheight, 15).attr({
fill: "r(.5,.9)#39c-#036",
stroke: "none"
});
bcontrols[i].shine = paper.ellipse(15 + (35 * i), yheight, 14, 14).attr({
fill: "r(.5,.1)#ccc-#ccc",
stroke: "none",
opacity: 0
});
bcontrols[i].index = i;
bcontrols[i].shine.index = i;
bcontrols[i].shine.mouseover(function (e) {
this.insertBefore(bcontrols[this.index]);
});
bcontrols[i].mouseout(function () {
this.insertBefore(bcontrols[this.index].shine);
});
/* Called from Raphael buttons */
bcontrols[i].click(function () {
alert("Hello you just clicked " + this.index);
});
}
Run Code Online (Sandbox Code Playgroud)
接下来,您需要了解有关旋转集的更多信息:
var s = paper.set();
s.push(paper.rect(10, 10, 30, 30, 10).attr({fill:'red'}));
s.push(paper.rect(50, 10, 30, 30, 5).attr({fill:'blue'}));
s.push(paper.rect(90, 10, 30, 30).attr({fill:'orange'}));
s.animate({rotation: "360 65 25"}, 2000);
Run Code Online (Sandbox Code Playgroud)
这显示了最后一行上"set"的旋转度和旋转中心.
我的其他拉斐尔资源网站旨在补充文档(除其他外):
http://www.irunmywebsite.com/raphael/raphaelsource.html
您可以在不改变的情况下运行上述2个代码示例:
http://raphaeljs.com/playground.html
我希望这有助于......