日期:2014-05-16  浏览次数:20464 次

使用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:


?

?

1 楼 zsm605 2012-02-29  
a1有什么用呢?
2 楼 zsm605 2012-02-29  
不加进去,好像也没什么关系啊