使用Raphael 画图(三) 事件 (javascript)

这章展示事件例子。

 下图是官方API的事件:

 

例子:

var butt1 = paper.set();
        var a1 = paper.circle(24.833, 26.917, 26.667).attr({fill: "#fff", opacity: 0});
        var a2 = paper.circle(24.833, 26.917, 26.667).attr({stroke: "black", fill: "#fff", "fill-opacity": .4, "stroke-width": 2}); 
        var a3 = paper.path("M12.582,9.551C3.251,16.237,0.921,29.021,7.08,38.564l-2.36,1.689l4.893,2.262l4.893,2.262l-0.568-5.36l-0.567-5.359l-2.365,1.694c-4.657-7.375-2.83-17.185,4.352-22.33c7.451-5.338,17.817-3.625,23.156,3.824c5.337,7.449,3.625,17.813-3.821,23.152l2.857,3.988c9.617-6.893,11.827-20.277,4.935-29.896C35.591,4.87,22.204,2.658,12.582,9.551z").attr({stroke: "none", fill: "#000"});
        butt1.push(a1,a2,a3);
        
        //为a2设置触发相应事件后做什么。
        butt1[1].click(function () {
            alert('where amazing happens!');
        }).mouseover(function () {
            butt1[2].stop().attr({fill: "orange"});
        }).mouseout(function () {
            butt1[2].animate({fill: "black"}, 300);
        });        
        
        butt1.translate(150,160);
        
        var butt2 = paper.set();
        var r = paper.rect(150,100,100,50);
        r.attr({stroke:'red','stroke-width':2,title:'模块一',fill:'#ccc'});
        var t = paper.text(200, 125, "where\n amazing\n happens!");//text
        t.attr({fill:'blue'});
        
        butt2.push(r,t);
        
        //这是另一种写法
        butt2[0].mouseover(function (event) {
            butt2[1].attr({fill: "green"});
        });
        
        butt2[0].mouseout(function (event) {
            butt2[1].attr({fill: "blue"});
        });

运行效果图1:


运行效果图2:


 

运行效果图3:


 原文:http://czpae86.iteye.com/blog/819183

转载于:https://www.cnblogs.com/kt520/p/4049605.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值