X-Git-Url: http://git.roojs.org/?p=raphael;a=blobdiff_plain;f=reference.html;h=cb0d1295fe9e38f4a8bd406199efeb1e5a97a10b;hp=49e9b6dd2514f1b3c27dc8de654a4e93ad8bfcda;hb=a8d0f3fa261b5dbd47dd6cc6c3391d5d90e5068f;hpb=65792bb06561d6ccf45a7e99712de8889958e848 diff --git a/reference.html b/reference.html index 49e9b6d..cb0d129 100644 --- a/reference.html +++ b/reference.html @@ -56,14 +56,139 @@
// Each of the following examples create a canvas that is 320px wide by 200px high
-// Canvas is created at the viewport's 10,50 coordinate
+// Canvas is created at the viewportâs 10,50 coordinate
var paper = Raphael(10, 50, 320, 200);
-// Canvas is created at the top left corner of the #notepad element (or its top right corner in dir="rtl" elements)
+// Canvas is created at the top left corner of the #notepad element
+// (or its top right corner in dir="rtl" elements)
var paper = Raphael(document.getElementById("notepad"), 320, 200);
// Same as above
var paper = Raphael("notepad", 320, 200);
// Image dump
-var set = Raphael(["notepad", 320, 200, {type: "rect", x: 10, y: 10, width: 25, height: 25, stroke: "#f00"}, {type: "text", x: 30, y: 40, text: "Dump"}]);
+var set = Raphael(["notepad", 320, 200, {
+ type: "rect",
+ x: 10,
+ y: 10,
+ width: 25,
+ height: 25,
+ stroke: "#f00"
+}, {
+ type: "text",
+ x: 30,
+ y: 40,
+ text: "Dump"
+}]);
+ + Draws a circle. +
+var c = paper.circle(50, 50, 40);
+ + Draws a rectangle. +
++// regular rectangle
+var c = paper.rect(10, 10, 50, 50);
+// rectangle with rounded corners
+var c = paper.rect(40, 40, 50, 50, 10);
+ Draws an ellipse. +
+var c = paper.ellipse(50, 50, 40, 20);
+ + Embeds an image into the SVG/VML canvas. +
+var c = paper.image("apple.png", 10, 10, 80, 80);
+ + Creates array-like object to keep and operate couple of elements at once. Warning: it doesnât create any elements for itself in the page. +
++var st = paper.set();
+st.push( + paper.circle(10, 10, 5), + paper.circle(30, 10, 5) +);
+st.attr({fill: "red"});
+ Draws a text string. If you need line breaks, put â\nâ in the string. +
+var t = paper.text(50, 50, "Raphaël\nkicks\nbutt!");
+ + Creates a path element by given path data string. +
+var c = paper.path("M10 10L90 90");
+// draw a diagonal line:
+// move to 10,10, line to 90,90
var c = paper.circle(10, 10, 10); // draw a circle at coordinate 10,10 with radius of 10
-c.node.onclick = function () { c.attr("fill", "red"); };
+ // draw a circle at coordinate 10,10 with radius of 10
+var c = paper.circle(10, 10, 10);
+c.node.onclick = function () {
+ c.attr("fill", "red");
+};
Raphael.el.cross = function () {
this.attr({fill: "red"});
- this.paper.path("M10,10L50,50M50,10L10,50").attr({stroke: "red"});
+ this.paper.path("M10,10L50,50M50,10L10,50")
+ .attr({stroke: "red"});
}
var c = paper.circle(10, 10, 10);
-c.translate(10, 10); // moves the circle down the canvas, in a diagonal line
+// moves the circle 10 px to the right and down
+c.translate(10, 10);
var c = paper.circle(10, 10, 10);
-c.scale(1.5, 1.5); // makes the circle 1.5 times larger
-c.scale(.5, .75); // makes the circle half as wide, and 75% as high
+// makes the circle 1.5 times larger
+c.scale(1.5, 1.5);
+// makes the circle half as wide, and 75% as high
+c.scale(.5, .75);
var c = paper.circle(10, 10, 10);
-c.attr("fill", "black"); // using strings
-c.attr({fill: "#000", stroke: "#f00", opacity: 0.5}); // using params object
-c.attr({fill: "90-#fff-#000", "stroke-dasharray": "-..", "clip-rect": "10, 10, 100, 100"});
+// using strings
+c.attr("fill", "black");
+// using params object
+c.attr({fill: "#000", stroke: "#f00", opacity: 0.5});
+c.attr({
+ fill: "90-#fff-#000",
+ "stroke-dasharray": "-..",
+ "clip-rect": "10, 10, 100, 100"
+});
Animates element along the given path. As an option it could rotate element along the path.
@@ -326,15 +465,34 @@ r.animateWith(c, {x: 20}, 2000); e.attr({rx: 4, ry: 4}); }); }); -
- Moves the element so it is the closest to the viewerâs eyes, on top of other elements.
+ Similar to animateAlong
. Animates element along the given path, starting from the end of it.
+
+ Sets or resets the function that will be called on each stage of the animation.
++var c = paper.circle(10, 10, 10);
-c.toFront();
var p = r.path("M10,50c0,50,80-50,80,0c0,50-80-50-80,0z"),
+ p2 = r.path(),
+ e = r.ellipse(10, 50, 4, 4).attr({stroke: "none", fill: "#f00"}).onAnimation(function () {
+ p2.attr({path: "M50,10L" + e.attr("cx") + "," + e.attr("cy")});
+ }),
+ b = r.rect(0, 0, 620, 400).attr({stroke: "none", fill: "#000", opacity: 0}).click(function () {
+ e.attr({rx: 5, ry: 3}).animateAlong(p, 4000, true, function () {
+ e.attr({rx: 4, ry: 4});
+ });
+ });
Path specific method. Returns point description at given length.
@@ -427,7 +586,7 @@ var c = r.clone();var p = r.path("M100,100c0,50 100-50 100,0c0,50 -100-50 -100,0z");
+ var p = r.path("M10,50c0,50,80-50,80,0c0,50-80-50-80,0z");
var point = p.getPointAtLength(30);
r.circle(point.x, point.y, 3);
Returned object format:
@@ -436,6 +595,22 @@ var c = r.clone();
+ Path specific method. Returns the subpath string of a given path. +
+var p = r.path("M10,50c0,50,80-50,80,0c0,50-80-50-80,0z");
+ var path = p.getSubpath(10, 60);
+ r.path(path).attr({stroke: "#f00"});
var txt = r.print(10, 50, "print", r.getFont("Museo"), 30).attr({fill: "#fff"});
// following line will paint first letter in red
txt[0].attr({fill: "#f00"});
- - Draws a circle. -
-var c = paper.circle(50, 50, 40);
- - Draws a rectangle. -
--// regular rectangle
-var c = paper.rect(10, 10, 50, 50);
-// rectangle with rounded corners
-var c = paper.rect(40, 40, 50, 50, 10);
- Draws an ellipse. -
-var c = paper.ellipse(50, 50, 40, 20);
- - Embeds an image into the SVG/VML canvas. -
-var c = paper.image("apple.png", 10, 10, 80, 80);
- - Creates array-like object to keep and operate couple of elements at once. Warning: it doesnât create any elements for itself in the page. -
--var st = paper.set();
-st.push(paper.circle(10, 10, 5), paper.circle(30, 10, 5));
-st.attr({fill: "red"});
- Draws a text string. If you need line breaks, put â\nâ in the string. -
-var t = paper.text(50, 50, "Raphaël\nkicks\nbutt!");
- - Initialises path drawing. You can specify a path by supplying the path data as a second argument. -
-var c = paper.path("M10 10L90 90");
-// draw a diagonal line: move to 10,10, line to 90,90
Raphael.fn.arrow = function (x1, y1, x2, y2, size) {
- return this.path(// some code here);
+ return this.path( ... );
};
// or create namespace
Raphael.fn.mystuff = {
@@ -683,18 +750,21 @@ paper.circle(100, 100, 20).red();
You could specify colour in this formats:
- - Colour name (âredâ, âgreenâ, âcornflowerblueâ, etc)
- - #â¢â¢â¢ â shortened HTML colour: (â#000â, â#fc0â, etc)
- - #â¢â¢â¢â¢â¢â¢ â full length HTML colour: (â#000000â, â#bd2300â)
- - rgb(â¢â¢â¢, â¢â¢â¢, â¢â¢â¢) â red, green and blue channelsâ values: (ârgb(200, 100, 0)â)
- - rgb(â¢â¢â¢%, â¢â¢â¢%, â¢â¢â¢%) â same as above, but in %: (ârgb(100%, 175%, 0%)â)
- - hsb(â¢â¢â¢, â¢â¢â¢, â¢â¢â¢) â hue, saturation and brightness values: (âhsb(0.5, 0.25, 1)â)
+ - Colour name (âredâ, âgreenâ, âcornflowerblueâ, etc)
+ - #â¢â¢â¢ â shortened HTML colour: (â#000â, â#fc0â, etc)
+ - #â¢â¢â¢â¢â¢â¢ â full length HTML colour: (â#000000â, â#bd2300â)
+ - rgb(â¢â¢â¢, â¢â¢â¢, â¢â¢â¢) â red, green and blue channelsâ values: (ârgb(200, 100, 0)â)
+ - rgb(â¢â¢â¢%, â¢â¢â¢%, â¢â¢â¢%) â same as above, but in %: (ârgb(100%, 175%, 0%)â)
+ - hsb(â¢â¢â¢, â¢â¢â¢, â¢â¢â¢) â hue, saturation and brightness values: (âhsb(0.5, 0.25, 1)â)
- hsb(â¢â¢â¢%, â¢â¢â¢%, â¢â¢â¢%) â same as above, but in %
- hsl(â¢â¢â¢, â¢â¢â¢, â¢â¢â¢) â same as hsb
- hsl(â¢â¢â¢%, â¢â¢â¢%, â¢â¢â¢%) â same as hsb
Usage
- paper.circle(100, 100, 20).attr({fill: "hsb(1, 255, 200)", stroke: "red"});
+ paper.circle(100, 100, 20).attr({
+ fill: "hsb(1, 255, 200)",
+ stroke: "red"
+});
safari
@@ -715,6 +785,42 @@ paper.circle(100, 100, 20).red();
â¦
})(Raphael.ninja());
+ + You can attach events to elements by using element.node and your favourite library ($(circle.node).click(â¦)) or you can use built-in methods: +
+element.click(function (event) {
+ this.attr({fill: "red"});
+});
+element.dblclick(function (event) {
+ this.attr({fill: "red"});
+});
+element.mousedown(function (event) {
+ this.attr({fill: "red"});
+});
+element.mousemove(function (event) {
+ this.attr({fill: "red"});
+});
+element.mouseout(function (event) {
+ this.attr({fill: "red"});
+});
+element.mouseover(function (event) {
+ this.attr({fill: "red"});
+});
+element.mouseup(function (event) {
+ this.attr({fill: "red"});
+});
+element.hover(function (event) {
+ this.attr({fill: "red"});
+}, function (event) {
+ this.attr({fill: "black"});
+});
+ + To unbind events use the same method names with âunâ prefix, i.e. element.unclick(f); +
Raphael
circle
+ rect
+ ellipse
+ image
+ set
+ text
+ path
+ node
animateAlong
animateAlongBack
+ getBBox
getPointAtLength
getSubpathsAtLength
+ getSubpath
setSize
@@ -817,27 +947,6 @@ paper.circle(100, 100, 20).red();
print
circle
- rect
- ellipse
- image
- set
- text
- path
-