如何使用 Raphael.js 旋转 div?

发布于 2024-08-10 02:07:15 字数 387 浏览 3 评论 0原文

我是 Raphael 的新手,我真的很困惑,我想使用 Raphael 的按钮来旋转 div 及其内容。

理想情况下,我希望有一个平滑的动画,当单击按钮时,动画从 0 度变为 -90 度,然后当再次单击按钮时,动画将反转。我想我会更改鼠标单击时的 id 或类,以便我可以对两个动画使用相同的按钮。这明智吗?

我真的需要一些帮助,我的沙盒位于 http://jsbin.com/isijo/ ,你可以在 http://jsbin.com/isijo/edit 进行编辑

非常感谢您的帮助。

I am brand new to Raphael and am really stuck, I would like to rotate a div and its contents, using a button, with Raphael.

Ideally, I would like to have a smooth animation that goes from 0 degrees to -90 degrees when the button is clicked, then when the button is clicked again, the animation would reverse. I think I will change the id or class on mouse click so that I can use the same button for both animations. Would that be wise?

I really would like some help please, my Sandbox is at http://jsbin.com/isijo/ and you can edit it at http://jsbin.com/isijo/edit

Many thanks in advance for any help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

云柯 2024-08-17 02:07:15

您好,欢迎来到拉斐尔!

我已经研究 Raphael 几个多月了,虽然文档不是很全面,但软件非常棒。

我一直在以多种方式将 Div 与 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);

    });
}

接下来您需要了解有关旋转集的更多信息:

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);

这显示了最后一个“集”的旋转程度和旋转中心线。

我的附加 Raphael 资源网站旨在补充文档(除其他外):

http://www. irunmywebsite.com/raphael/raphaelsource.html

您可以在此处运行上述 2 个代码示例,无需更改:

http://raphaeljs.com/playground.html

我希望这有帮助......

Hello and welcome to Raphael!

I have been looking at Raphael for more than a few months and although the documentation is not very comprehensive the software is brilliant.

I have been mixing Divs with Raphael objects in many ways and have got a "feel" for what works and what does not work.

I am recommending that you do not try rotating divs but (instead) Raphael objects.

First of all you could make a shiney set of Raphael buttons using this "tweakable" code below..

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);

    });
}

Next you need to know more about rotating Sets:

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);

This shows the degree of rotation and the centre of rotation of the "set" on the last line.

My additional Raphael resources website which aims to supplement documentation (Amongst other things):

http://www.irunmywebsite.com/raphael/raphaelsource.html

Heres where you can run the above 2 code examples without alteration:

http://raphaeljs.com/playground.html

I'm hoping this helped...

止于盛夏 2024-08-17 02:07:15

据我所知,没有办法将 div 转换为 Raphael 对象。由于 Raphael 旋转命令仅为 Raphael 对象定义,因此最好的选择是在 Raphael 而不是 HTML 中创建 div 的主要元素(图像、文本、按钮等),将它们放在一个集合中,并且,如该集合是拉斐尔对象,旋转该集合。

To my knowledge, there is no way to convert a div into a Raphael object. Since the Raphael rotate command is only defined for Raphael objects, your best bet is to create the major elements of your div (images, text, buttons and all) in Raphael instead of HTML, put them together in a single set, and, as the set is a Raphael object, rotate the set.

め七分饶幸 2024-08-17 02:07:15

请参阅在 CSS 和 IE 过滤器中旋转 div。这与 SVG 不同,因此如果您需要更多布局魔法,Raphael 形状可能是最佳选择。您应该能够将 JQuery 与 Raphael 配合使用来在窗口中操作两者,但我对 Raphael 来说是全新的,从未这样做过。

Consult Rotate a div in CSS and in IE filters. This is not the same as SVG, so if you need more layout magic, Raphael shapes are likely the way to go. You should be able to used JQuery in concert with Raphael to manipulate both in your window, but I am brand new to Raphael and have never done so.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文