summaryrefslogtreecommitdiffstats
path: root/src/fx.js
diff options
context:
space:
mode:
authorwout <wout@impinc.co.uk>2013-03-05 09:32:33 +0000
committerwout <wout@impinc.co.uk>2013-03-05 09:32:33 +0000
commit31e0a8f178185208aaf71702dadc1dbc8a6ff0eb (patch)
treee4f7dea76ae75fe4cc2207d2d96a27672b4e877a /src/fx.js
parentca15876e17a1acce4909837af97d97995d0f5b23 (diff)
downloadsvg.js-31e0a8f178185208aaf71702dadc1dbc8a6ff0eb.tar.gz
svg.js-31e0a8f178185208aaf71702dadc1dbc8a6ff0eb.zip
Fix in animate().center()0.8
Diffstat (limited to 'src/fx.js')
-rw-r--r--src/fx.js92
1 files changed, 46 insertions, 46 deletions
diff --git a/src/fx.js b/src/fx.js
index 7aa60a9..35f95bc 100644
--- a/src/fx.js
+++ b/src/fx.js
@@ -11,11 +11,11 @@ SVG.extend(SVG.FX, {
duration = duration == null ? 1000 : duration
ease = ease || '<>'
- var akeys, tkeys, tvalues,
- element = this.target,
- fx = this,
- start = (new Date).getTime(),
- finish = start + duration
+ var akeys, tkeys, tvalues
+ , element = this.target
+ , fx = this
+ , start = (new Date).getTime()
+ , finish = start + duration
/* start animation */
this.interval = setInterval(function(){
@@ -84,9 +84,9 @@ SVG.extend(SVG.FX, {
}, duration > 10 ? 10 : duration)
return this
- },
+ }
// Add animatable attributes
- attr: function(a, v, n) {
+, attr: function(a, v, n) {
if (typeof a == 'object')
for (var key in a)
this.attr(key, a[key])
@@ -95,55 +95,55 @@ SVG.extend(SVG.FX, {
this.attrs[a] = { from: this.target.attr(a), to: v }
return this;
- },
+ }
// Add animatable transformations
- transform: function(o) {
+, transform: function(o) {
for (var key in o)
this.trans[key] = { from: this.target.trans[key], to: o[key] }
return this
- },
+ }
// Add animatable move
- move: function(x, y) {
+, move: function(x, y) {
var box = this.target.bbox()
this._move = {
- x: { from: box.x, to: x },
- y: { from: box.y, to: y }
+ x: { from: box.x, to: x }
+ , y: { from: box.y, to: y }
}
return this
- },
+ }
// Add animatable size
- size: function(width, height) {
+, size: function(width, height) {
var box = this.target.bbox()
this._size = {
- width: { from: box.width, to: width },
- height: { from: box.height, to: height }
+ width: { from: box.width, to: width }
+ , height: { from: box.height, to: height }
}
return this
- },
+ }
// Add animatable center
- center: function(x, y) {
+, center: function(x, y) {
var box = this.target.bbox()
this._move = {
- x: { from: box.cx, to: x },
- y: { from: box.cy, to: y }
+ x: { from: box.cx, to: x - box.width / 2 }
+ , y: { from: box.cy, to: y - box.height / 2 }
}
return this
- },
+ }
// Callback after animation
- after: function(after) {
+, after: function(after) {
this._after = after
return this
- },
+ }
// Stop running animation
- stop: function() {
+, stop: function() {
/* stop current animation */
clearInterval(this.interval)
@@ -155,9 +155,9 @@ SVG.extend(SVG.FX, {
this._after = null
return this
- },
+ }
// Private: at position according to from and to
- _at: function(o, pos) {
+, _at: function(o, pos) {
/* if a number, recalculate pos */
return typeof o.from == 'number' ?
o.from + (o.to - o.from) * pos :
@@ -168,9 +168,9 @@ SVG.extend(SVG.FX, {
/* for all other values wait until pos has reached 1 to return the final value */
pos < 1 ? o.from : o.to
- },
+ }
// Private: tween color
- _color: function(o, pos) {
+, _color: function(o, pos) {
var from, to
/* convert FROM hex to rgb */
@@ -181,39 +181,39 @@ SVG.extend(SVG.FX, {
/* tween color and return hex */
return this._r2h({
- r: ~~(from.r + (to.r - from.r) * pos),
- g: ~~(from.g + (to.g - from.g) * pos),
- b: ~~(from.b + (to.b - from.b) * pos)
+ r: ~~(from.r + (to.r - from.r) * pos)
+ , g: ~~(from.g + (to.g - from.g) * pos)
+ , b: ~~(from.b + (to.b - from.b) * pos)
})
- },
+ }
// Private: convert hex to rgb object
- _h2r: function(hex) {
+, _h2r: function(hex) {
/* parse full hex */
var match = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(this._fh(hex))
/* if the hex is successfully parsed, return it in rgb, otherwise return black */
return match ? {
- r: parseInt(match[1], 16),
- g: parseInt(match[2], 16),
- b: parseInt(match[3], 16)
+ r: parseInt(match[1], 16)
+ , g: parseInt(match[2], 16)
+ , b: parseInt(match[3], 16)
} : { r: 0, g: 0, b: 0 }
- },
+ }
// Private: convert rgb object to hex string
- _r2h: function(rgb) {
+, _r2h: function(rgb) {
return '#' + this._c2h(rgb.r) + this._c2h(rgb.g) + this._c2h(rgb.b)
- },
+ }
// Private: convert component to hex
- _c2h: function(c) {
+, _c2h: function(c) {
var hex = c.toString(16)
return hex.length == 1 ? '0' + hex : hex
- },
+ }
// Private: force potential 3-based hex to 6-based
- _fh: function(hex) {
+, _fh: function(hex) {
return hex.length == 4 ?
[ '#',
- hex.substring(1, 2), hex.substring(1, 2),
- hex.substring(2, 3), hex.substring(2, 3),
- hex.substring(3, 4), hex.substring(3, 4)
+ hex.substring(1, 2), hex.substring(1, 2)
+ , hex.substring(2, 3), hex.substring(2, 3)
+ , hex.substring(3, 4), hex.substring(3, 4)
].join('') : hex
}