Raphael JavaScript Library
-
Upload
learningtech -
Category
Technology
-
view
378 -
download
2
Transcript of Raphael JavaScript Library
![Page 1: Raphael JavaScript Library](https://reader036.fdocuments.in/reader036/viewer/2022082808/5555d2d3d8b42a711f8b4afd/html5/thumbnails/1.jpg)
Raphaël JavaScript Library
By Jax
![Page 2: Raphael JavaScript Library](https://reader036.fdocuments.in/reader036/viewer/2022082808/5555d2d3d8b42a711f8b4afd/html5/thumbnails/2.jpg)
Step
• Over View
• Create Paper
• Create Element
• Sample run 1
• Element animate
• Element event
• Sample run 2
• drag
• Sample run 3
![Page 3: Raphael JavaScript Library](https://reader036.fdocuments.in/reader036/viewer/2022082808/5555d2d3d8b42a711f8b4afd/html5/thumbnails/3.jpg)
Over View
• Raphael
• Paper
• Element
• Animation
• Matrix
• Set
![Page 4: Raphael JavaScript Library](https://reader036.fdocuments.in/reader036/viewer/2022082808/5555d2d3d8b42a711f8b4afd/html5/thumbnails/4.jpg)
Create Paper
var paper = Raphael("elementId", 840, 480);
var paper = Raphael(element, 840, 480);
var paper = Raphael(10, 10, 840, 480);
![Page 5: Raphael JavaScript Library](https://reader036.fdocuments.in/reader036/viewer/2022082808/5555d2d3d8b42a711f8b4afd/html5/thumbnails/5.jpg)
Create Elementpaper.circle(x, y, radius) paper.ellipse(x, y, radiusX, radiusY)
paper.rect(x, y, width, height, [radius])
paper.text(x, y, text)
paper.path("M10 10 L90 90")
paper.image(src, x, y, width, height)
![Page 6: Raphael JavaScript Library](https://reader036.fdocuments.in/reader036/viewer/2022082808/5555d2d3d8b42a711f8b4afd/html5/thumbnails/6.jpg)
Paper.path
http://raphaeljs.com/reference.html#Paper.path
Command Name Parameters
M moveto (x y)+
Z closepath (none)
L lineto (x y)+
H horizontal lineto x+
V vertical lineto y+
C curveto (x1 y1 x2 y2 x y)+
S smooth curveto (x2 y2 x y)+
Q quadratic Bézier curveto (x1 y1 x y)+
T smooth quadratic Bézier curveto (x y)+
A elliptical arc(rx ry x-axis-rotation large-arc-flag sweep-flag x y)+
R Catmull-Rom curveto* x1 y1 (x y)+
![Page 7: Raphael JavaScript Library](https://reader036.fdocuments.in/reader036/viewer/2022082808/5555d2d3d8b42a711f8b4afd/html5/thumbnails/7.jpg)
Raphael.fn
Raphael.fn.arrow = function (x1, y1, x2, y2, size) { return this.path( ... );
};
var paper = Raphael(10, 10, 630, 480);
// then use it paper.arrow(10, 10, 30, 30, 5);
![Page 8: Raphael JavaScript Library](https://reader036.fdocuments.in/reader036/viewer/2022082808/5555d2d3d8b42a711f8b4afd/html5/thumbnails/8.jpg)
Element.attr
// get Element.attr('attrName') Element.attr(['attrName1', 'attrName2'])
// set Element.attr('attrName', 'value') Element.attr({ 'attrName': 'value' })
![Page 9: Raphael JavaScript Library](https://reader036.fdocuments.in/reader036/viewer/2022082808/5555d2d3d8b42a711f8b4afd/html5/thumbnails/9.jpg)
Element attributes • cx • cy • r • rx • ry • x • y
• fill • fill-opacity • height • width • opacity • path • stroke • stroke-opacity • stroke-width
http://raphaeljs.com/reference.html#Element.attr
![Page 10: Raphael JavaScript Library](https://reader036.fdocuments.in/reader036/viewer/2022082808/5555d2d3d8b42a711f8b4afd/html5/thumbnails/10.jpg)
![Page 11: Raphael JavaScript Library](https://reader036.fdocuments.in/reader036/viewer/2022082808/5555d2d3d8b42a711f8b4afd/html5/thumbnails/11.jpg)
Sample run 1• In JsBin
<script src="https://rawgithub.com/DmitryBaranovskiy/raphael/master/raphael-min.js" type="text/javascript" charset="utf-8"></script>
![Page 12: Raphael JavaScript Library](https://reader036.fdocuments.in/reader036/viewer/2022082808/5555d2d3d8b42a711f8b4afd/html5/thumbnails/12.jpg)
Element animate
Element.animate(attrObj, ms, [easing])
• “linear” • “<” or “easeIn” or “ease-in” • “>” or “easeOut” or “ease-out” • “<>” or “easeInOut” or “ease-in-out” • “backIn” or “back-in” • “backOut” or “back-out” • “elastic” • “bounce”
![Page 13: Raphael JavaScript Library](https://reader036.fdocuments.in/reader036/viewer/2022082808/5555d2d3d8b42a711f8b4afd/html5/thumbnails/13.jpg)
Element event
• click (handler)• dblclick (handler)• drag(onmove, onstart, onend, [mcontext], [scontext],
[econtext])• hover(f_in, f_out, [in_context], [out_context])• mousedown (handler)• mousemove (handler)• mouseout (handler)• mouseover (handler)• mouseup (handler)• onDragOver (handler)
![Page 14: Raphael JavaScript Library](https://reader036.fdocuments.in/reader036/viewer/2022082808/5555d2d3d8b42a711f8b4afd/html5/thumbnails/14.jpg)
Sample run 2
• Use animate 200ms on hover
![Page 15: Raphael JavaScript Library](https://reader036.fdocuments.in/reader036/viewer/2022082808/5555d2d3d8b42a711f8b4afd/html5/thumbnails/15.jpg)
Element Other Method
• data(key, [value])• removeData([key])• glow([glow])• clone()• remove()• show()• hide()• toBack()• toFront()
• rotate(deg, [cx], [cy])• scale(sx, sy, [cx], [cy])• transform([tstr])• translate(dx, dy)
• resume([anim])• status([anim], [value])• stop([anim])
![Page 16: Raphael JavaScript Library](https://reader036.fdocuments.in/reader036/viewer/2022082808/5555d2d3d8b42a711f8b4afd/html5/thumbnails/16.jpg)
drag
paper.circle(50, 50, 20).attr('fill', 'red').drag(function (dx, dy, x, y, event) {
this.attr({ cx: this.ox + dx, cy: this.oy + dy }); }, function (x, y, event) {
this.ox = this.attr("cx"); this.oy = this.attr("cy");
});
![Page 17: Raphael JavaScript Library](https://reader036.fdocuments.in/reader036/viewer/2022082808/5555d2d3d8b42a711f8b4afd/html5/thumbnails/17.jpg)
Sample run 3