2015-07-02 13:57:26 +08:00
|
|
|
|
/**
|
|
|
|
|
* Created by jljsj on 15/6/24.
|
|
|
|
|
*/
|
2015-11-18 23:01:22 +08:00
|
|
|
|
$(function() {
|
|
|
|
|
var $S = function(typename) {
|
2015-07-31 13:56:33 +08:00
|
|
|
|
if (typename.indexOf("<") >= 0) {
|
|
|
|
|
var node = $(typename);
|
|
|
|
|
var node_m = $(document.createElementNS("http://www.w3.org/2000/svg", node[0].tagName.toLowerCase()));
|
|
|
|
|
//var node_b=typename.replace(/<[^\s]*|[>,/>]*/gi,"");
|
|
|
|
|
for (var i = 0; i < node[0].attributes.length; i++) {
|
|
|
|
|
node_m.attr(node[0].attributes[i].name, node[0].attributes[i].value);
|
|
|
|
|
}
|
|
|
|
|
node_m.html(node.html());
|
|
|
|
|
return node_m
|
|
|
|
|
}
|
|
|
|
|
return $(document.createElementNS("http://www.w3.org/2000/svg", typename))
|
|
|
|
|
};
|
2015-11-18 23:01:22 +08:00
|
|
|
|
var SVG = (function() {
|
|
|
|
|
var s_node = function(s) {
|
2015-07-31 13:56:33 +08:00
|
|
|
|
if (s) {
|
|
|
|
|
this.node = $S(s);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
var n = s_node.prototype = {
|
|
|
|
|
_x: 0,
|
|
|
|
|
_y: 0,
|
|
|
|
|
_scaleX: 1,
|
|
|
|
|
_scaleY: 1,
|
|
|
|
|
_rotation: 0,
|
|
|
|
|
_skewX: 0,
|
|
|
|
|
_skewY: 0,
|
|
|
|
|
set id(id) {
|
|
|
|
|
this.attr("id", id)
|
|
|
|
|
},
|
|
|
|
|
get id() {
|
|
|
|
|
return this.attr("id")
|
|
|
|
|
},
|
|
|
|
|
set x(x) {
|
|
|
|
|
this.setTransform(x, this._y, this._scaleX, this._scaleY, this._rotation, this._skewX, this._skewY);
|
|
|
|
|
},
|
|
|
|
|
get x() {
|
|
|
|
|
return this._x
|
|
|
|
|
},
|
|
|
|
|
set y(y) {
|
|
|
|
|
this.setTransform(this._x, y, this._scaleX, this._scaleY, this._rotation, this._skewX, this._skewY);
|
|
|
|
|
},
|
|
|
|
|
get y() {
|
|
|
|
|
return this._y
|
|
|
|
|
},
|
|
|
|
|
set scale(x) {
|
|
|
|
|
this.setTransform(this._x, this._y, x, x, this._rotation, this._skewX, this._skewY);
|
|
|
|
|
},
|
|
|
|
|
get scale() {
|
2015-11-18 23:01:22 +08:00
|
|
|
|
return this._scaleX == this._scaleY ? this._scaleX : {
|
|
|
|
|
scaleX: this._scaleX,
|
|
|
|
|
scaleY: this._scaleY
|
|
|
|
|
}
|
2015-07-31 13:56:33 +08:00
|
|
|
|
},
|
|
|
|
|
set scaleX(x) {
|
|
|
|
|
this.setTransform(this._x, this._y, x, this._scaleY, this._rotation, this._skewX, this._skewY);
|
|
|
|
|
},
|
|
|
|
|
get scaleX() {
|
|
|
|
|
return this._scaleX
|
|
|
|
|
},
|
|
|
|
|
set scaleY(y) {
|
|
|
|
|
this.setTransform(this._x, this._y, this._scaleX, y, this._rotation, this._skewX, this._skewY);
|
|
|
|
|
},
|
|
|
|
|
get scaleY() {
|
|
|
|
|
return this._scaleY
|
|
|
|
|
},
|
|
|
|
|
set rotation(r) {
|
|
|
|
|
this.setTransform(this._x, this._y, this._scaleX, this._scaleY, r, this._skewX, this._skewY);
|
|
|
|
|
},
|
|
|
|
|
get rotation() {
|
|
|
|
|
return this._rotation
|
|
|
|
|
},
|
|
|
|
|
set skewX(x) {
|
|
|
|
|
this.setTransform(this._x, this._y, this._scaleX, this._scaleY, this._rotation, x, this._skewY);
|
|
|
|
|
},
|
|
|
|
|
get skewX() {
|
|
|
|
|
return this._skewX
|
|
|
|
|
},
|
|
|
|
|
set skewY(y) {
|
|
|
|
|
this.setTransform(this._x, this._y, this._scaleX, this._scaleY, this._rotation, this._skewX, y);
|
|
|
|
|
},
|
|
|
|
|
get skewY() {
|
|
|
|
|
return this._skewY
|
|
|
|
|
},
|
|
|
|
|
set alpha(a) {
|
|
|
|
|
this.attr("opacity", a.toString())
|
|
|
|
|
},
|
|
|
|
|
get alpha() {
|
|
|
|
|
return Number(this.attr("opacity")) >= 0 ? Number(this.attr("opacity")) : 1
|
|
|
|
|
},
|
|
|
|
|
set mouseEnabled(Bool) {
|
|
|
|
|
if (Bool) {
|
|
|
|
|
this.attr("cursor", "pointer")
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
get mouseEnabled() {
|
|
|
|
|
return !!this.attr("cursor");
|
|
|
|
|
}
|
|
|
|
|
};
|
2015-11-18 23:01:22 +08:00
|
|
|
|
n.attr = function(o, d) {
|
2015-07-31 13:56:33 +08:00
|
|
|
|
return d ? this.node.attr(o, d) : this.node.attr(o)
|
|
|
|
|
};
|
2015-11-18 23:01:22 +08:00
|
|
|
|
n.css = function(o, d) {
|
2015-07-31 13:56:33 +08:00
|
|
|
|
return d ? this.node.css(o, d) : this.node.css(o);
|
|
|
|
|
};
|
2015-11-18 23:01:22 +08:00
|
|
|
|
n.children = function() {
|
2015-07-31 13:56:33 +08:00
|
|
|
|
return this.node.children()
|
|
|
|
|
};
|
2015-11-18 23:01:22 +08:00
|
|
|
|
n.find = function(s) {
|
2015-07-31 13:56:33 +08:00
|
|
|
|
return this.node.find(s);
|
|
|
|
|
};
|
2015-11-18 23:01:22 +08:00
|
|
|
|
n.addEventListener = function(event, func) {
|
2015-07-31 13:56:33 +08:00
|
|
|
|
return this.node.bind(event, func);
|
|
|
|
|
};
|
2015-11-18 23:01:22 +08:00
|
|
|
|
n.bind = function(event, func) {
|
2015-07-31 13:56:33 +08:00
|
|
|
|
return this.node.bind(event, func);
|
|
|
|
|
};
|
2015-11-18 23:01:22 +08:00
|
|
|
|
n.setTransform = function(x, y, scaleX, scaleY, rotation, skewX, skewY) {
|
|
|
|
|
var x = x || 0,
|
|
|
|
|
y = y || 0,
|
|
|
|
|
scaleX = scaleX >= 0 ? scaleX : 1,
|
|
|
|
|
scaleY = scaleY >= 0 ? scaleY : 1,
|
|
|
|
|
rotation = rotation || 0,
|
|
|
|
|
skewX = skewX || 0,
|
|
|
|
|
skewY = skewY || 0;
|
2015-07-31 13:56:33 +08:00
|
|
|
|
this._x = x, this._y = y, this._scaleX = scaleX, this._scaleY = scaleY,
|
|
|
|
|
this._rotation = rotation, this._skewX = skewX, this._skewY = skewY;
|
|
|
|
|
var DEG_TO_RAD = Math.PI / 180;
|
|
|
|
|
var Matrix = {
|
2015-11-18 23:01:22 +08:00
|
|
|
|
a: 1,
|
|
|
|
|
b: 0,
|
|
|
|
|
c: 0,
|
|
|
|
|
d: 1,
|
|
|
|
|
tx: 0,
|
|
|
|
|
ty: 0,
|
|
|
|
|
initialize: function(a, b, c, d, tx, ty) {
|
2015-07-31 13:56:33 +08:00
|
|
|
|
var a1 = this.a;
|
|
|
|
|
var b1 = this.b;
|
|
|
|
|
var c1 = this.c;
|
|
|
|
|
var d1 = this.d;
|
|
|
|
|
this.a = a * a1 + b * c1;
|
|
|
|
|
this.b = a * b1 + b * d1;
|
|
|
|
|
this.c = c * a1 + d * c1;
|
|
|
|
|
this.d = c * b1 + d * d1;
|
|
|
|
|
this.tx = tx * a1 + ty * c1 + this.tx;
|
|
|
|
|
this.ty = tx * b1 + ty * d1 + this.ty;
|
|
|
|
|
return this
|
2015-07-02 13:57:26 +08:00
|
|
|
|
}
|
2015-07-31 13:56:33 +08:00
|
|
|
|
};
|
|
|
|
|
if (rotation % 360) {
|
|
|
|
|
var r = rotation * DEG_TO_RAD;
|
|
|
|
|
var cos = Math.cos(r);
|
|
|
|
|
var sin = Math.sin(r);
|
|
|
|
|
} else {
|
|
|
|
|
cos = 1;
|
|
|
|
|
sin = 0;
|
|
|
|
|
}
|
|
|
|
|
var t = Matrix;
|
|
|
|
|
if (skewX || skewY) {
|
|
|
|
|
skewX = skewX * DEG_TO_RAD || 0;
|
|
|
|
|
skewY = skewY * DEG_TO_RAD || 0;
|
|
|
|
|
t.initialize(cos * scaleX, sin * scaleX, -sin * scaleY, cos * scaleY, 0, 0);
|
|
|
|
|
t.initialize(Math.cos(skewY), Math.sin(skewY), -Math.sin(skewX), Math.cos(skewX), x, y);
|
|
|
|
|
} else {
|
|
|
|
|
t.initialize(cos * scaleX, sin * scaleX, -sin * scaleY, cos * scaleY, x, y);
|
|
|
|
|
}
|
|
|
|
|
var val = "matrix(" + t.a + "," + t.b + "," + t.c + "," + t.d + "," + t.tx + "," + t.ty + ")";
|
|
|
|
|
this.attr("transform", val)
|
|
|
|
|
};
|
2015-11-18 23:01:22 +08:00
|
|
|
|
n.addChild = function(elem) {
|
2015-07-31 13:56:33 +08:00
|
|
|
|
if (elem.node) this.node.append(elem.node);
|
|
|
|
|
else this.node.append(elem);
|
|
|
|
|
};
|
2015-11-18 23:01:22 +08:00
|
|
|
|
n.clear = function(index) {
|
2015-07-31 13:56:33 +08:00
|
|
|
|
if (index >= 0) {
|
|
|
|
|
this.node.children().eq(index).remove();
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
return this.node.children().remove();
|
2015-07-02 13:57:26 +08:00
|
|
|
|
};
|
2015-11-18 23:01:22 +08:00
|
|
|
|
n.setFilter = function(dom) {
|
2015-07-31 13:56:33 +08:00
|
|
|
|
this.attr("filter", "url(#" + dom.attr("id") + ")")
|
|
|
|
|
};
|
2015-11-18 23:01:22 +08:00
|
|
|
|
n.setClipPath = function(dom) {
|
2015-07-31 13:56:33 +08:00
|
|
|
|
this.attr("clip-path", "url(#" + dom.attr("id") + ")");
|
|
|
|
|
};
|
2015-11-18 23:01:22 +08:00
|
|
|
|
var SectorStr = function(point, r, angle, startAngle, inr) {
|
2015-07-31 13:56:33 +08:00
|
|
|
|
angle = (Math.abs(angle) > 360) ? 360 : angle;
|
|
|
|
|
var flag = angle > 180 ? 1 : 0;
|
|
|
|
|
startAngle = startAngle * Math.PI / 180;
|
2015-11-18 23:01:22 +08:00
|
|
|
|
var str = ""; //"M"+point.x+" "+point.y;
|
2015-07-31 13:56:33 +08:00
|
|
|
|
str += " M" + (point.x + r * Math.cos(startAngle)) + " " + (point.y + r * Math.sin(startAngle))
|
|
|
|
|
var angleA, cx, cy;
|
|
|
|
|
if (angle >= 360) {
|
|
|
|
|
angleA = angle / 2;
|
|
|
|
|
angleA = angleA * Math.PI / 180;
|
|
|
|
|
angleA = angleA + startAngle;
|
|
|
|
|
for (var i = 0; i < 2; i++) {
|
|
|
|
|
cx = point.x + r * Math.cos(angleA + i * Math.PI);
|
|
|
|
|
cy = point.y + r * Math.sin(angleA + i * Math.PI);
|
|
|
|
|
str += "A" + r + " " + r + " 0 1 1 " + cx + " " + cy;
|
2015-07-02 13:57:26 +08:00
|
|
|
|
}
|
2015-07-31 13:56:33 +08:00
|
|
|
|
str += " Z";
|
|
|
|
|
return str;
|
|
|
|
|
}
|
|
|
|
|
angle = angle * Math.PI / 180;
|
|
|
|
|
angleA = angle + startAngle;
|
2015-07-02 13:57:26 +08:00
|
|
|
|
|
2015-07-31 13:56:33 +08:00
|
|
|
|
cx = point.x + r * Math.cos(angleA);
|
|
|
|
|
cy = point.y + r * Math.sin(angleA);
|
|
|
|
|
str += "A" + r + " " + r + " 0 " + flag + " 1 " + cx + " " + cy;
|
|
|
|
|
if (angle < Math.PI * 2) {
|
|
|
|
|
str += " L" + point.x + " " + point.y
|
|
|
|
|
}
|
|
|
|
|
//画内圆;
|
|
|
|
|
if (inr) {
|
|
|
|
|
cx = point.x + inr * Math.cos(angleA);
|
|
|
|
|
cy = point.y + inr * Math.sin(angleA);
|
|
|
|
|
str += "L" + cx + " " + cy;
|
|
|
|
|
cx = point.x + inr * Math.cos(startAngle);
|
|
|
|
|
cy = point.y + inr * Math.sin(startAngle);
|
|
|
|
|
str += "A" + inr + " " + inr + " 0 " + flag + " 0 " + cx + " " + cy;
|
|
|
|
|
}
|
|
|
|
|
str += " Z";
|
|
|
|
|
return str;
|
|
|
|
|
};
|
2015-11-18 23:01:22 +08:00
|
|
|
|
var Sprite = function(s) {
|
2015-07-31 13:56:33 +08:00
|
|
|
|
if (s) {
|
|
|
|
|
this.node = $S(s);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
var sp = Sprite.prototype = new s_node();
|
2015-07-02 13:57:26 +08:00
|
|
|
|
|
2015-11-18 23:01:22 +08:00
|
|
|
|
sp.drawRect = function(obj) {
|
2015-07-31 13:56:33 +08:00
|
|
|
|
var t = new SVG.Sprite("rect");
|
|
|
|
|
t.attr(obj).appendTo(this.node);
|
|
|
|
|
return t
|
|
|
|
|
};
|
2015-11-18 23:01:22 +08:00
|
|
|
|
sp.drawCirc = function(obj) {
|
2015-07-31 13:56:33 +08:00
|
|
|
|
var t = new SVG.Sprite("circle");
|
|
|
|
|
t.attr(obj).appendTo(this.node);
|
|
|
|
|
return t
|
|
|
|
|
};
|
2015-11-18 23:01:22 +08:00
|
|
|
|
sp.drawPolygon = function(obj) {
|
2015-07-31 13:56:33 +08:00
|
|
|
|
var t = new SVG.Sprite("polygon");
|
|
|
|
|
t.attr(obj).appendTo(this.node);
|
|
|
|
|
return t
|
|
|
|
|
};
|
2015-11-18 23:01:22 +08:00
|
|
|
|
sp.drawPath = function(obj) {
|
2015-07-31 13:56:33 +08:00
|
|
|
|
var t = new SVG.Sprite("path");
|
|
|
|
|
t.attr(obj).appendTo(this.node);
|
|
|
|
|
return t
|
|
|
|
|
};
|
2015-11-18 23:01:22 +08:00
|
|
|
|
sp.drawEllipse = function(obj) {
|
2015-07-31 13:56:33 +08:00
|
|
|
|
var t = new SVG.Sprite("ellipse");
|
|
|
|
|
t.attr(obj).appendTo(this.node);
|
|
|
|
|
return t
|
|
|
|
|
};
|
2015-11-18 23:01:22 +08:00
|
|
|
|
sp.drawSector = function(point, r, angle, startAngle, color, line, lineColor) {
|
2015-07-31 13:56:33 +08:00
|
|
|
|
var str = SectorStr(point, r, angle, startAngle, 1);
|
|
|
|
|
var m = $S("path").attr("fill", color);
|
|
|
|
|
if (line) {
|
2015-11-18 23:01:22 +08:00
|
|
|
|
m.attr({
|
|
|
|
|
stroke: lineColor,
|
|
|
|
|
"stroke-width": line
|
|
|
|
|
});
|
2015-07-31 13:56:33 +08:00
|
|
|
|
}
|
|
|
|
|
m.attr("d", str).appendTo(this.node);
|
|
|
|
|
return m
|
|
|
|
|
};
|
2015-11-18 23:01:22 +08:00
|
|
|
|
sp.drawAnnular = function(point, r, inr, angle, startAngle, color, line, lineColor) {
|
2015-07-31 13:56:33 +08:00
|
|
|
|
var str = SectorStr(point, r, angle, startAngle, inr);
|
|
|
|
|
var m = $S("path").attr("fill", color);
|
|
|
|
|
if (line) {
|
2015-11-18 23:01:22 +08:00
|
|
|
|
m.attr({
|
|
|
|
|
stroke: lineColor,
|
|
|
|
|
"stroke-width": line
|
|
|
|
|
});
|
2015-07-31 13:56:33 +08:00
|
|
|
|
}
|
|
|
|
|
m.attr("d", str).appendTo(this.node);
|
|
|
|
|
return m
|
|
|
|
|
};
|
2015-07-02 13:57:26 +08:00
|
|
|
|
|
2015-07-31 13:56:33 +08:00
|
|
|
|
function svg(id) {
|
|
|
|
|
this.initialize(id);
|
|
|
|
|
}
|
2015-07-02 13:57:26 +08:00
|
|
|
|
|
2015-07-31 13:56:33 +08:00
|
|
|
|
var s = svg.prototype = new Sprite();
|
2015-11-18 23:01:22 +08:00
|
|
|
|
s.initialize = function(id) {
|
2015-07-31 13:56:33 +08:00
|
|
|
|
this.node = $S("svg");
|
2015-11-18 23:01:22 +08:00
|
|
|
|
this.attr({
|
|
|
|
|
"width": "100%",
|
|
|
|
|
"height": "100%"
|
|
|
|
|
});
|
2015-07-31 13:56:33 +08:00
|
|
|
|
this.defs = new Sprite("defs");
|
|
|
|
|
this.addChild(this.defs);
|
|
|
|
|
if (id)
|
|
|
|
|
$(id).append(this.node);
|
|
|
|
|
else
|
2015-07-02 13:57:26 +08:00
|
|
|
|
return this;
|
|
|
|
|
};
|
2015-07-31 13:56:33 +08:00
|
|
|
|
var filter = {
|
2015-11-18 23:01:22 +08:00
|
|
|
|
blur: function(x, y) {
|
2015-07-31 13:56:33 +08:00
|
|
|
|
if (x == null) {
|
|
|
|
|
x = 2;
|
|
|
|
|
}
|
|
|
|
|
var def = y == null ? x : [x, y];
|
|
|
|
|
var t = document.createElementNS("http://www.w3.org/2000/svg", "feGaussianBlur");
|
|
|
|
|
t.setAttribute("stdDeviation", def);
|
|
|
|
|
var filter = $S("filter");
|
2015-11-18 23:01:22 +08:00
|
|
|
|
filter.attr({
|
|
|
|
|
x: "-50%",
|
|
|
|
|
y: "-50%",
|
|
|
|
|
"width": "200%",
|
|
|
|
|
"height": "200%"
|
|
|
|
|
});
|
2015-07-31 13:56:33 +08:00
|
|
|
|
filter.append(t);
|
|
|
|
|
Object.defineProperty(filter, "id", {
|
2015-11-18 23:01:22 +08:00
|
|
|
|
get: function() {
|
2015-07-31 13:56:33 +08:00
|
|
|
|
return filter.attr("id");
|
|
|
|
|
},
|
2015-11-18 23:01:22 +08:00
|
|
|
|
set: function(id) {
|
2015-07-31 13:56:33 +08:00
|
|
|
|
filter.attr("id", id);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
return filter
|
|
|
|
|
},
|
2015-11-18 23:01:22 +08:00
|
|
|
|
goo: function(blur) {
|
2015-07-31 13:56:33 +08:00
|
|
|
|
var t = document.createElementNS("http://www.w3.org/2000/svg", "feGaussianBlur");
|
|
|
|
|
t.setAttribute("in", "SourceGraphic");
|
|
|
|
|
t.setAttribute("stdDeviation", blur);
|
|
|
|
|
t.setAttribute("result", "blur");
|
|
|
|
|
var matrix = document.createElementNS("http://www.w3.org/2000/svg", "feColorMatrix");
|
|
|
|
|
matrix.setAttribute("in", "blur");
|
|
|
|
|
matrix.setAttribute("mode", "matrix");
|
|
|
|
|
matrix.setAttribute("values", "1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 18 -6");
|
|
|
|
|
matrix.setAttribute("result", "goo");
|
|
|
|
|
var com = document.createElementNS("http://www.w3.org/2000/svg", "feComposite");
|
|
|
|
|
com.setAttribute("in", "SourceGraphic");
|
|
|
|
|
com.setAttribute("in2", "goo");
|
|
|
|
|
com.setAttribute("operator", "atop");
|
|
|
|
|
var filter = $S("filter");
|
|
|
|
|
filter.append([t, matrix, com]);
|
|
|
|
|
return filter
|
|
|
|
|
},
|
2015-11-18 23:01:22 +08:00
|
|
|
|
mask: function(tb, obj) {
|
2015-07-31 13:56:33 +08:00
|
|
|
|
var t = $S(tb);
|
|
|
|
|
t.attr(obj);
|
|
|
|
|
var cp = $S("clipPath");
|
|
|
|
|
cp.append(t);
|
|
|
|
|
Object.defineProperty(cp, "id", {
|
2015-11-18 23:01:22 +08:00
|
|
|
|
get: function() {
|
2015-07-31 13:56:33 +08:00
|
|
|
|
return cp.attr("id");
|
|
|
|
|
},
|
2015-11-18 23:01:22 +08:00
|
|
|
|
set: function(id) {
|
2015-07-31 13:56:33 +08:00
|
|
|
|
cp.attr("id", id);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
//var cp=document.createElementNS("http://www.w3.org/2000/svg","clipPath");//$S("clippath");
|
|
|
|
|
//cp.appendChild(t[0]);
|
|
|
|
|
//Object.defineProperty(cp,"id",{
|
|
|
|
|
// get:function (){
|
|
|
|
|
// return cp.getAttribute("id");
|
|
|
|
|
// },
|
|
|
|
|
// set:function (id){
|
|
|
|
|
// cp.setAttribute("id",id);
|
|
|
|
|
// }
|
|
|
|
|
//});
|
|
|
|
|
return cp;
|
|
|
|
|
}
|
|
|
|
|
};
|
2015-11-18 23:01:22 +08:00
|
|
|
|
var text = function(_text, _data) {
|
2015-07-31 13:56:33 +08:00
|
|
|
|
this.node = $S("text");
|
|
|
|
|
this.node.text(_text);
|
|
|
|
|
if (_data) {
|
|
|
|
|
this.node.attr(_data);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
var t = text.prototype = new s_node;
|
2015-11-18 23:01:22 +08:00
|
|
|
|
t.tspan = function(_text, _data) {
|
2015-07-31 13:56:33 +08:00
|
|
|
|
this.node = $S("tspan");
|
|
|
|
|
this.node.text(_text);
|
|
|
|
|
if (_data) {
|
|
|
|
|
this.node.attr(_data);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
var ts = t.tspan.prototype = new s_node();
|
2015-07-03 17:00:59 +08:00
|
|
|
|
|
2015-07-31 13:56:33 +08:00
|
|
|
|
svg.SectorStr = SectorStr;
|
|
|
|
|
svg.filter = filter;
|
|
|
|
|
svg.Sprite = Sprite;
|
|
|
|
|
svg.Text = text;
|
|
|
|
|
svg.Text.tSpan = t.tspan;
|
|
|
|
|
return svg
|
|
|
|
|
}());
|
2015-11-18 23:01:22 +08:00
|
|
|
|
var Point = function(x, y) {
|
2015-07-31 13:56:33 +08:00
|
|
|
|
this.x = x;
|
|
|
|
|
this.y = y;
|
|
|
|
|
return this;
|
|
|
|
|
};
|
|
|
|
|
var T = TweenMax;
|
2015-11-18 23:01:22 +08:00
|
|
|
|
var _playBox = function(svg, startFunc, pauseFunc) {
|
2015-07-31 13:56:33 +08:00
|
|
|
|
var playBox = new SVG.Sprite("g");
|
|
|
|
|
playBox.mouseEnabled = true;
|
2015-07-03 17:00:59 +08:00
|
|
|
|
|
2015-11-18 23:01:22 +08:00
|
|
|
|
playBox.drawRect({
|
|
|
|
|
width: "100%",
|
|
|
|
|
height: "100%",
|
|
|
|
|
fill: "rgba(0,0,0,.35)"
|
|
|
|
|
});
|
2015-07-31 13:56:33 +08:00
|
|
|
|
var playBtn = new SVG.Sprite("g");
|
|
|
|
|
playBox.addChild(playBtn);
|
2015-11-18 23:01:22 +08:00
|
|
|
|
playBtn.drawCirc({
|
|
|
|
|
r: 30,
|
|
|
|
|
fill: "rgba(255,255,255,1)"
|
|
|
|
|
});
|
2015-07-03 17:00:59 +08:00
|
|
|
|
|
2015-07-31 13:56:33 +08:00
|
|
|
|
var playPoints = {
|
|
|
|
|
play: "M-10 -15 L15 0 L-10 15 L-10 0Z M-10 -15 L15 0 L-10 15 L-10 0Z",
|
|
|
|
|
pause: "M-12 -15 L-3 -15 L-3 15 L-12 15Z M3 -15 L12 -15 L12 15 L3 15Z"
|
2015-07-03 17:00:59 +08:00
|
|
|
|
};
|
2015-11-18 23:01:22 +08:00
|
|
|
|
var shanjiao = playBtn.drawPath({
|
|
|
|
|
d: playPoints.play,
|
|
|
|
|
fill: "#999"
|
|
|
|
|
});
|
2015-07-31 13:56:33 +08:00
|
|
|
|
var bBool = false;
|
2015-11-18 23:01:22 +08:00
|
|
|
|
var animate_p3 = function(p, _arr) {
|
2015-07-31 13:56:33 +08:00
|
|
|
|
var a_arr = [];
|
|
|
|
|
for (var i = 0; i < _arr.length; i++) {
|
|
|
|
|
a_arr.push(_arr[i].x, _arr[i].y)
|
|
|
|
|
}
|
|
|
|
|
for (var i = 0; i < a_arr.length; i++) {
|
|
|
|
|
if (i == 0 || i == 8) {
|
|
|
|
|
a_arr[i] = "M" + a_arr[i];
|
|
|
|
|
} else if (i == 2 || i == 4 || i == 6 || i == 12 || i == 14) {
|
|
|
|
|
a_arr[i] = "L" + a_arr[i];
|
|
|
|
|
} else if (i == 7 || i == 15) {
|
|
|
|
|
a_arr[i] = a_arr[i] + "Z";
|
2015-07-02 13:57:26 +08:00
|
|
|
|
}
|
2015-07-31 13:56:33 +08:00
|
|
|
|
}
|
|
|
|
|
p.attr({
|
|
|
|
|
d: a_arr.join().replace(/,/g, " ")
|
|
|
|
|
});
|
2015-07-02 13:57:26 +08:00
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
2015-07-31 13:56:33 +08:00
|
|
|
|
function twennBtn(p, arr, c_arr) {
|
|
|
|
|
for (var i = 0; i < arr.length; i++) {
|
|
|
|
|
T.killTweensOf(arr[i]);
|
|
|
|
|
T.to(arr[i], .6, {
|
|
|
|
|
x: c_arr[i].x,
|
|
|
|
|
y: c_arr[i].y,
|
|
|
|
|
delay: Math.random() * .2,
|
|
|
|
|
onUpdate: animate_p3,
|
|
|
|
|
onUpdateParams: [p, arr],
|
|
|
|
|
ease: Elastic.easeOut
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-07-02 13:57:26 +08:00
|
|
|
|
|
2015-11-18 23:01:22 +08:00
|
|
|
|
playBox.addEventListener("click", function(e) {
|
2015-07-31 13:56:33 +08:00
|
|
|
|
var _a = playPoints.play.replace(/[MLZ]/g, "").split(" ");
|
|
|
|
|
var _b = playPoints.pause.replace(/[MLZ]/g, "").split(" ");
|
2015-11-18 23:01:22 +08:00
|
|
|
|
var _arr = [],
|
|
|
|
|
_barr = [];
|
2015-07-31 13:56:33 +08:00
|
|
|
|
for (var i = 0; i < _a.length; i += 2) {
|
2015-11-18 23:01:22 +08:00
|
|
|
|
var a = {},
|
|
|
|
|
b = {};
|
2015-07-31 13:56:33 +08:00
|
|
|
|
a.x = _a[i];
|
|
|
|
|
a.y = _a[i + 1];
|
|
|
|
|
b.x = _b[i];
|
|
|
|
|
b.y = _b[i + 1];
|
|
|
|
|
_arr.push(a);
|
|
|
|
|
_barr.push(b);
|
|
|
|
|
}
|
|
|
|
|
if (!bBool) {
|
|
|
|
|
twennBtn(shanjiao, _arr, _barr);
|
2015-11-18 23:01:22 +08:00
|
|
|
|
T.to(playBox, .5, {
|
|
|
|
|
delay: .3,
|
|
|
|
|
alpha: 0,
|
|
|
|
|
onComplete: startFunc
|
|
|
|
|
});
|
2015-07-31 13:56:33 +08:00
|
|
|
|
bBool = true;
|
|
|
|
|
} else {
|
|
|
|
|
twennBtn(shanjiao, _barr, _arr);
|
2015-11-18 23:01:22 +08:00
|
|
|
|
T.to(playBox, .5, {
|
|
|
|
|
alpha: 1,
|
|
|
|
|
onStart: pauseFunc
|
|
|
|
|
});
|
2015-07-31 13:56:33 +08:00
|
|
|
|
bBool = false
|
|
|
|
|
}
|
|
|
|
|
});
|
2015-11-18 23:01:22 +08:00
|
|
|
|
|
2015-07-31 13:56:33 +08:00
|
|
|
|
function resize() {
|
|
|
|
|
playBtn.x = svg.node.width() / 2;
|
|
|
|
|
playBtn.y = svg.node.height() / 2;
|
|
|
|
|
}
|
2015-07-02 13:57:26 +08:00
|
|
|
|
|
2015-07-31 13:56:33 +08:00
|
|
|
|
resize();
|
|
|
|
|
$(window).bind("resize", resize);
|
|
|
|
|
return playBox;
|
|
|
|
|
};
|
2015-11-18 23:01:22 +08:00
|
|
|
|
var newMotion = function(id, obj) {
|
2015-07-31 13:56:33 +08:00
|
|
|
|
if (!id || !obj) {
|
|
|
|
|
throw new Error("数据错误");
|
|
|
|
|
}
|
|
|
|
|
var self = this;
|
|
|
|
|
self.box = $(id);
|
2015-11-18 23:01:22 +08:00
|
|
|
|
self.box.css({
|
|
|
|
|
"width": 800
|
|
|
|
|
});
|
2015-07-31 13:56:33 +08:00
|
|
|
|
if (self.box.width() < 500) {
|
|
|
|
|
self.box.css("height", 600);
|
|
|
|
|
} else {
|
|
|
|
|
self.box.css("height", 300)
|
|
|
|
|
}
|
|
|
|
|
self.data = obj;
|
|
|
|
|
self.svg = new SVG(id);
|
|
|
|
|
self.svg.css("background-color", "#f3f3f3");
|
|
|
|
|
self.w = self.box.width();
|
|
|
|
|
self.h = self.box.height();
|
|
|
|
|
self.tweenArr = [];
|
|
|
|
|
self.t_time = .5;
|
|
|
|
|
self.d_time = .5;
|
|
|
|
|
self.tweenAllTime = self.t_time * 2 + self.d_time;
|
2015-07-02 13:57:26 +08:00
|
|
|
|
|
2015-07-31 13:56:33 +08:00
|
|
|
|
self.addElement();
|
2015-07-02 13:57:26 +08:00
|
|
|
|
|
2015-07-31 13:56:33 +08:00
|
|
|
|
function resize(e) {
|
|
|
|
|
self.windowResize(self)
|
|
|
|
|
}
|
2015-07-02 13:57:26 +08:00
|
|
|
|
|
2015-07-31 13:56:33 +08:00
|
|
|
|
resize();
|
|
|
|
|
$(window).bind("resize", resize);
|
|
|
|
|
};
|
|
|
|
|
var nm = newMotion.prototype = {};
|
2015-11-18 23:01:22 +08:00
|
|
|
|
nm.windowResize = function(self) {
|
2015-07-31 13:56:33 +08:00
|
|
|
|
var s = self.box.parent().width() / 800 > 1 ? 1 : self.box.parent().width() / 800;
|
2015-11-18 23:01:22 +08:00
|
|
|
|
self.box.css({
|
|
|
|
|
"transform": "scale(" + s + ")",
|
|
|
|
|
"transform-origin": "0 0"
|
|
|
|
|
});
|
2015-07-31 13:56:33 +08:00
|
|
|
|
};
|
2015-11-18 23:01:22 +08:00
|
|
|
|
nm.addElement = function() {
|
2015-07-31 13:56:33 +08:00
|
|
|
|
var self = this;
|
|
|
|
|
//绘制坐标系统;
|
|
|
|
|
self.coords = new SVG.Sprite("g");
|
|
|
|
|
self.svg.addChild(self.coords);
|
|
|
|
|
var coordsStr = "M80 50 L80 250 L480 250";
|
2015-11-18 23:01:22 +08:00
|
|
|
|
self.coords.drawPath({
|
|
|
|
|
d: coordsStr,
|
|
|
|
|
fill: "none",
|
|
|
|
|
"stroke-width": 2,
|
|
|
|
|
stroke: "#d9d9d9"
|
|
|
|
|
});
|
|
|
|
|
var timerTxt = new SVG.Text("timer", {
|
|
|
|
|
fill: "#999"
|
|
|
|
|
});
|
2015-07-31 13:56:33 +08:00
|
|
|
|
self.coords.addChild(timerTxt);
|
|
|
|
|
timerTxt.x = 240;
|
|
|
|
|
timerTxt.y = 275;
|
2015-11-18 23:01:22 +08:00
|
|
|
|
var yaxis = new SVG.Text("Y-axis", {
|
|
|
|
|
fill: "#999"
|
|
|
|
|
});
|
2015-07-31 13:56:33 +08:00
|
|
|
|
yaxis.width = 20;
|
|
|
|
|
yaxis.x = 20;
|
|
|
|
|
yaxis.y = 150;
|
|
|
|
|
self.coords.addChild(yaxis);
|
|
|
|
|
//动画示例元素;
|
|
|
|
|
self.tweenMc = new SVG.Sprite("g");
|
|
|
|
|
if (self.data.mask) {
|
2015-11-18 23:01:22 +08:00
|
|
|
|
var mask = new SVG.filter.mask("rect", {
|
|
|
|
|
width: 260,
|
|
|
|
|
height: 200
|
|
|
|
|
});
|
2015-07-31 13:56:33 +08:00
|
|
|
|
mask.id = "mask";
|
|
|
|
|
self.svg.defs.addChild(mask);
|
|
|
|
|
self.tweenMc.setClipPath(mask);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
self.svg.addChild(self.tweenMc);
|
|
|
|
|
self.tweenMc.x = 500;
|
|
|
|
|
self.tweenMc.y = 50;
|
|
|
|
|
//坐标线;
|
|
|
|
|
/**
|
|
|
|
|
* 以三次贝塞尔曲线
|
|
|
|
|
* 时间长4秒
|
|
|
|
|
* -分三段-
|
|
|
|
|
* linear
|
|
|
|
|
* .5--.5--.5
|
|
|
|
|
*/
|
2015-11-18 23:01:22 +08:00
|
|
|
|
var c_w = 340,
|
|
|
|
|
c_h = 180,
|
|
|
|
|
c_x = 100,
|
|
|
|
|
c_y = 250,
|
|
|
|
|
ct_y = 70,
|
|
|
|
|
t_w = c_w * (self.t_time / self.tweenAllTime),
|
|
|
|
|
tt_w = t_w + c_x,
|
|
|
|
|
d_w = (self.t_time + self.d_time) / self.tweenAllTime;
|
2015-07-31 13:56:33 +08:00
|
|
|
|
|
|
|
|
|
for (var i = 0; i < self.data.lineData.length; i++) {
|
|
|
|
|
var tb = new SVG.Sprite("g");
|
|
|
|
|
self.coords.addChild(tb);
|
|
|
|
|
var str = "M80 250";
|
|
|
|
|
var open = self.data.lineData[i].open || self.data.lineData[i].openEaseName || "Linear";
|
|
|
|
|
/*if (open.length !== 4 && open.length !== 0 && typeof open !== 'string') {
|
|
|
|
|
throw new Error(open + "数据错误");
|
|
|
|
|
}*/
|
|
|
|
|
if (typeof open !== 'string' && open.length !== 0 && open.length === 4) {
|
|
|
|
|
str += "L100 250" + "C" + (open[0] * t_w + c_x) + "," + (c_y - open[1] * c_h) + " " + (open[2] * t_w + c_x) + "," + (c_y - open[3] * c_h) + " " + tt_w + "," + ct_y
|
|
|
|
|
} else if (typeof open === 'string') {
|
|
|
|
|
var _ease = EaseLookup.find(open);
|
|
|
|
|
if (_ease) {
|
|
|
|
|
str += 'L100 250';
|
|
|
|
|
for (var ii = 0; ii < t_w; ii++) {
|
2015-11-18 23:01:22 +08:00
|
|
|
|
var at = _ease.getRatio(ii / t_w); //延用grennsock的缓运。。
|
2015-07-31 13:56:33 +08:00
|
|
|
|
//console.log(1-Tween.Bounce.easeOut(ii,100,-100,t_w)/100,at);
|
|
|
|
|
str += 'L' + (c_x + ii) + "," + (c_y - c_h * at);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2015-08-12 15:38:54 +08:00
|
|
|
|
if (open !== 'null') {
|
|
|
|
|
str += "L100 250" + "L" + tt_w + "," + ct_y;
|
|
|
|
|
} else {
|
|
|
|
|
str += "M100 250";
|
|
|
|
|
}
|
2015-07-02 13:57:26 +08:00
|
|
|
|
}
|
2015-07-31 13:56:33 +08:00
|
|
|
|
}
|
|
|
|
|
tb.drawPath({
|
|
|
|
|
d: str,
|
|
|
|
|
fill: "none",
|
|
|
|
|
"stroke-width": 2,
|
|
|
|
|
stroke: self.data.lineData[i].stroke || "#999",
|
|
|
|
|
"stroke-dasharray": "0 100%"
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var e_x = c_w * d_w + c_x;
|
|
|
|
|
str = "M" + tt_w + "," + ct_y + "L" + e_x + "," + ct_y;
|
|
|
|
|
tb.drawPath({
|
|
|
|
|
d: str,
|
|
|
|
|
fill: "none",
|
|
|
|
|
"stroke-width": 2,
|
|
|
|
|
stroke: self.data.lineData[i].stroke || "#999",
|
|
|
|
|
"stroke-dasharray": "0 100%"
|
|
|
|
|
});
|
|
|
|
|
var end = self.data.lineData[i].end || self.data.lineData[i].endEaseName || "Linear";
|
|
|
|
|
|
|
|
|
|
str = "M" + e_x + "," + ct_y;
|
|
|
|
|
if (typeof open !== 'string' && end.length !== 0 && end.length === 4) {
|
2015-11-18 23:01:22 +08:00
|
|
|
|
str += "C" + (end[0] * t_w + e_x) + "," + (end[1] * c_h + ct_y) + " " + (end[2] * t_w + e_x) + "," + (end[3] * c_h + ct_y) + " " + (c_w + c_x) + "," + c_y + "L" + (c_w + c_x + 20) + "," + c_y
|
2015-07-31 13:56:33 +08:00
|
|
|
|
} else if (typeof end === 'string') {
|
|
|
|
|
var e_ease = EaseLookup.find(end);
|
|
|
|
|
if (e_ease) {
|
|
|
|
|
for (var eii = 0; eii < t_w; eii++) {
|
|
|
|
|
var eat = e_ease.getRatio(eii / t_w);
|
2015-11-18 23:01:22 +08:00
|
|
|
|
str += 'L' + (e_x + eii) + "," + (c_h * eat + ct_y);
|
2015-07-31 13:56:33 +08:00
|
|
|
|
}
|
|
|
|
|
str += "L" + (c_w + c_x + 20) + "," + c_y;
|
|
|
|
|
} else {
|
2015-08-12 15:38:54 +08:00
|
|
|
|
//str += "L" + (c_w + c_x ) + "," + c_y + "L" + (c_w + c_x + 20) + "," + c_y;
|
|
|
|
|
if (end !== "null") {
|
2015-11-18 23:01:22 +08:00
|
|
|
|
str += "L" + (c_w + c_x) + "," + c_y + "L" + (c_w + c_x + 20) + "," + c_y;
|
2015-07-31 13:56:33 +08:00
|
|
|
|
} else {
|
|
|
|
|
str += "L" + e_x + "," + ct_y;
|
2015-08-12 15:38:54 +08:00
|
|
|
|
}
|
2015-07-02 13:57:26 +08:00
|
|
|
|
}
|
2015-07-31 13:56:33 +08:00
|
|
|
|
}
|
|
|
|
|
tb.drawPath({
|
|
|
|
|
d: str,
|
|
|
|
|
fill: "none",
|
|
|
|
|
"stroke-width": 2,
|
|
|
|
|
stroke: self.data.lineData[i].stroke || "#999",
|
|
|
|
|
"stroke-dasharray": "0 100%"
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
//元素插入盒子里;
|
|
|
|
|
var circ = new SVG.Sprite("circle");
|
2015-11-18 23:01:22 +08:00
|
|
|
|
circ.attr({
|
|
|
|
|
"r": 10,
|
|
|
|
|
fill: "none",
|
|
|
|
|
"stroke-width": 6,
|
|
|
|
|
stroke: self.data.lineData[i].stroke || "#999"
|
|
|
|
|
});
|
2015-07-31 13:56:33 +08:00
|
|
|
|
self.tweenMc.addChild(circ);
|
|
|
|
|
if (self.data.exposure == "left" || !self.data.exposure) {
|
|
|
|
|
circ.x = self.data.mask ? -20 : 20;
|
2015-11-18 23:01:22 +08:00
|
|
|
|
circ.y = 50 + i * 110; //self.data.mask?240:180;
|
2015-07-31 13:56:33 +08:00
|
|
|
|
} else if (self.data.exposure == "top") {
|
2015-11-18 23:01:22 +08:00
|
|
|
|
circ.x = 100 + i * 100; //self.data.mask?-20:20;
|
2015-07-31 13:56:33 +08:00
|
|
|
|
circ.y = self.data.mask ? -20 : 20;
|
|
|
|
|
} else if (self.data.exposure == "right") {
|
|
|
|
|
circ.x = self.data.mask ? 280 : 220;
|
2015-11-18 23:01:22 +08:00
|
|
|
|
circ.y = 50 + i * 110; //self.data.mask?240:180;
|
2015-07-31 13:56:33 +08:00
|
|
|
|
} else {
|
2015-11-18 23:01:22 +08:00
|
|
|
|
circ.x = 100 + i * 100; //self.data.mask?-20:20;
|
2015-07-31 13:56:33 +08:00
|
|
|
|
circ.y = self.data.mask ? 240 : 180;
|
|
|
|
|
}
|
2015-07-02 13:57:26 +08:00
|
|
|
|
|
2015-07-31 13:56:33 +08:00
|
|
|
|
}
|
2015-07-02 13:57:26 +08:00
|
|
|
|
|
2015-07-31 13:56:33 +08:00
|
|
|
|
//建播放按钮;
|
2015-11-18 23:01:22 +08:00
|
|
|
|
self.playBox = _playBox(self.svg, function() {
|
2015-07-31 13:56:33 +08:00
|
|
|
|
self.start(self);
|
2015-11-18 23:01:22 +08:00
|
|
|
|
}, function() {
|
2015-07-31 13:56:33 +08:00
|
|
|
|
self.pause(self);
|
|
|
|
|
});
|
|
|
|
|
self.svg.addChild(self.playBox);
|
|
|
|
|
};
|
2015-11-18 23:01:22 +08:00
|
|
|
|
nm.pause = function(self) {
|
2015-07-31 13:56:33 +08:00
|
|
|
|
for (var i = 0; i < self.tweenArr.length; i++) {
|
|
|
|
|
var tl = self.tweenArr[i];
|
|
|
|
|
tl.pause();
|
|
|
|
|
}
|
|
|
|
|
};
|
2015-11-18 23:01:22 +08:00
|
|
|
|
nm.resume = function(self) {
|
2015-07-31 13:56:33 +08:00
|
|
|
|
for (var i = 0; i < self.tweenArr.length; i++) {
|
|
|
|
|
var tl = self.tweenArr[i];
|
|
|
|
|
tl.resume();
|
|
|
|
|
}
|
|
|
|
|
};
|
2015-11-18 23:01:22 +08:00
|
|
|
|
nm.start = function(self) {
|
2015-07-31 13:56:33 +08:00
|
|
|
|
if (self.tweenArr.length) {
|
|
|
|
|
self.resume(self);
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
var lineBox = self.coords.find("g");
|
|
|
|
|
for (var i = 0; i < lineBox.length; i++) {
|
|
|
|
|
var m = lineBox.eq(i);
|
2015-11-18 23:01:22 +08:00
|
|
|
|
var tl = new TimelineMax({
|
|
|
|
|
repeat: -1,
|
|
|
|
|
repeatDelay: 1
|
|
|
|
|
});
|
2015-07-31 13:56:33 +08:00
|
|
|
|
self.tweenArr.push(tl);
|
|
|
|
|
for (var ii = 0; ii < m.find("path").length; ii++) {
|
|
|
|
|
var p = m.find("path").eq(ii);
|
|
|
|
|
var lineLength = p[0].getTotalLength();
|
2015-11-18 23:01:22 +08:00
|
|
|
|
var time = 1,
|
|
|
|
|
_ease = Power2.easeInOut;
|
2015-07-02 13:57:26 +08:00
|
|
|
|
|
2015-07-31 13:56:33 +08:00
|
|
|
|
if (ii == 0) {
|
|
|
|
|
time = self.t_time;
|
|
|
|
|
//_ease = EaseLookup.find(self.data.lineData[i].openEaseName);
|
2015-11-18 23:01:22 +08:00
|
|
|
|
} else if (ii == 1) {
|
2015-07-31 13:56:33 +08:00
|
|
|
|
time = self.d_time;
|
|
|
|
|
//_ease = Power0.easeNone;
|
2015-11-18 23:01:22 +08:00
|
|
|
|
} else {
|
2015-07-31 13:56:33 +08:00
|
|
|
|
time = self.t_time;
|
|
|
|
|
//_ease = EaseLookup.find(self.data.lineData[i].endEaseName);
|
|
|
|
|
}
|
|
|
|
|
/*if (!self.data.lineData[i].open.length) {
|
|
|
|
|
_ease = Linear.easeNone;
|
|
|
|
|
}*/
|
2015-11-18 23:01:22 +08:00
|
|
|
|
tl.add(T.to(p, time, {
|
|
|
|
|
"stroke-dasharray": lineLength + " 100%",
|
|
|
|
|
ease: Linear.easeNone
|
|
|
|
|
}));
|
2015-07-31 13:56:33 +08:00
|
|
|
|
//tl.to(p,time,{"stroke-dasharray":"100% 100%",ease: Power2.easeInOut})
|
|
|
|
|
}
|
|
|
|
|
//circ动画
|
2015-11-18 23:01:22 +08:00
|
|
|
|
var ctl = new TimelineMax({
|
|
|
|
|
repeat: -1,
|
|
|
|
|
repeatDelay: 1
|
|
|
|
|
});
|
2015-07-31 13:56:33 +08:00
|
|
|
|
var ciric = self.tweenMc.children().eq(i);
|
2015-07-02 13:57:26 +08:00
|
|
|
|
|
2015-07-31 13:56:33 +08:00
|
|
|
|
var oease = EaseLookup.find(self.data.lineData[i].openEaseName) || Linear.easeNone,
|
|
|
|
|
eease = EaseLookup.find(self.data.lineData[i].endEaseName) || Linear.easeNone;
|
|
|
|
|
//console.log(self.data.lineData[i].open,oease,eease,i);
|
|
|
|
|
//if(self.data.lineData[i].openEaseName=="Bounce.easeOut")
|
|
|
|
|
if (self.data.lineData[i].openEaseName && self.data.lineData[i].openEaseName.indexOf("Bounce") >= 0) {
|
|
|
|
|
if (self.data.lineData[i].openEaseName.indexOf("InOut") >= 0) {
|
|
|
|
|
oease = Bounce.easeInOut
|
|
|
|
|
} else if (self.data.lineData[i].openEaseName.indexOf("In") >= 0) {
|
|
|
|
|
oease = Bounce.easeIn
|
|
|
|
|
} else {
|
|
|
|
|
oease = Bounce.easeOut
|
2015-07-03 17:00:59 +08:00
|
|
|
|
}
|
2015-07-31 13:56:33 +08:00
|
|
|
|
}
|
2015-11-18 23:01:22 +08:00
|
|
|
|
var cx = {},
|
|
|
|
|
_x = {};
|
2015-07-31 13:56:33 +08:00
|
|
|
|
if (self.data.exposure == "left" || !self.data.exposure) {
|
2015-11-18 23:01:22 +08:00
|
|
|
|
_x = {
|
|
|
|
|
x: 240
|
|
|
|
|
};
|
|
|
|
|
cx = {
|
|
|
|
|
x: self.data.mask ? -20 : 20
|
|
|
|
|
};
|
2015-07-31 13:56:33 +08:00
|
|
|
|
} else if (self.data.exposure == "top") {
|
2015-11-18 23:01:22 +08:00
|
|
|
|
_x = {
|
|
|
|
|
y: 180
|
|
|
|
|
};
|
|
|
|
|
cx = {
|
|
|
|
|
y: self.data.mask ? -20 : 20
|
|
|
|
|
};
|
2015-07-31 13:56:33 +08:00
|
|
|
|
} else if (self.data.exposure == "right") {
|
2015-11-18 23:01:22 +08:00
|
|
|
|
_x = {
|
|
|
|
|
x: 20
|
|
|
|
|
};
|
|
|
|
|
cx = {
|
|
|
|
|
x: self.data.mask ? 280 : 220
|
|
|
|
|
};
|
2015-07-31 13:56:33 +08:00
|
|
|
|
} else {
|
2015-11-18 23:01:22 +08:00
|
|
|
|
_x = {
|
|
|
|
|
y: 20
|
|
|
|
|
};
|
|
|
|
|
cx = {
|
|
|
|
|
y: self.data.mask ? 240 : 180
|
|
|
|
|
};
|
2015-07-31 13:56:33 +08:00
|
|
|
|
}
|
2015-08-12 15:38:54 +08:00
|
|
|
|
if (self.data.lineData[i].openEaseName === "null" && self.data.lineData[i].endEaseName === "null") {
|
2015-07-31 13:56:33 +08:00
|
|
|
|
var t = cx;
|
|
|
|
|
cx = {};
|
|
|
|
|
cx.startAt = t;
|
|
|
|
|
cx.delay = self.d_time;
|
2015-08-12 15:38:54 +08:00
|
|
|
|
var tt = _x;
|
|
|
|
|
_x = {};
|
|
|
|
|
_x.startAt = tt;
|
|
|
|
|
} else if (self.data.lineData[i].openEaseName === "null") {
|
|
|
|
|
var tt = _x;
|
|
|
|
|
_x = {};
|
|
|
|
|
_x.startAt = tt;
|
2015-09-16 15:33:14 +08:00
|
|
|
|
cx.ease = eease, cx.delay = self.d_time;
|
2015-08-12 15:38:54 +08:00
|
|
|
|
} else if (self.data.lineData[i].endEaseName === "null") {
|
|
|
|
|
var t = cx;
|
|
|
|
|
cx = {};
|
|
|
|
|
cx.startAt = t;
|
|
|
|
|
cx.delay = self.d_time;
|
|
|
|
|
_x.ease = oease;
|
|
|
|
|
} else {
|
|
|
|
|
_x.ease = oease, cx.ease = eease, cx.delay = self.d_time;
|
2015-07-31 13:56:33 +08:00
|
|
|
|
}
|
|
|
|
|
ctl.to(ciric, self.t_time, _x).to(ciric, self.t_time, cx);
|
|
|
|
|
self.tweenArr.push(ctl);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
window.Motion = newMotion;
|
|
|
|
|
|
|
|
|
|
var motionVideo = {
|
2015-09-16 17:37:28 +08:00
|
|
|
|
video: ['https://t.alipayobjects.com/images/rmsweb/T1yHhhXfxkXXXXXXXX.webm', 'https://t.alipayobjects.com/images/rmsweb/T12I8gXexdXXXXXXXX.webm', 'https://t.alipayobjects.com/images/rmsweb/T1br0gXghtXXXXXXXX.webm', 'https://t.alipayobjects.com/images/rmsweb/T14q0hXbBdXXXXXXXX.webm'],
|
|
|
|
|
videoMp4: ['https://t.alipayobjects.com/images/rmsweb/T15IXhXlXbXXXXXXXX.mp4', 'https://t.alipayobjects.com/images/rmsweb/T1e0hgXcpdXXXXXXXX.mp4', 'https://t.alipayobjects.com/images/rmsweb/T1lcRgXb4gXXXXXXXX.mp4', 'https://t.alipayobjects.com/images/T1qWNhXkpeXXXXXXXX.mp4'],
|
2015-11-18 23:01:22 +08:00
|
|
|
|
init: function() {
|
2015-07-31 13:56:33 +08:00
|
|
|
|
var self = this;
|
|
|
|
|
self.videoBox = $(".video-player");
|
2015-09-16 17:37:28 +08:00
|
|
|
|
$('<video preload loop></video>').appendTo(self.videoBox);
|
2015-07-31 13:56:33 +08:00
|
|
|
|
for (var i = 0; i < self.videoBox.length; i++) {
|
|
|
|
|
var svg = new SVG();
|
|
|
|
|
self.videoBox.eq(i).append(svg.node);
|
|
|
|
|
var video = self.videoBox.eq(i).find("video");
|
2015-11-18 23:01:22 +08:00
|
|
|
|
if (video[0].canPlayType('video/webm; codecs="vp8.0, vorbis"')) {
|
|
|
|
|
$('<source src="' + self.video[i] + '" type="video/webm">').appendTo(video);
|
|
|
|
|
} else {
|
|
|
|
|
$('<source src="' + self.videoMp4[i] + '" type="video/mp4">').appendTo(video);
|
2015-09-16 17:37:28 +08:00
|
|
|
|
}
|
2015-11-18 23:01:22 +08:00
|
|
|
|
video.css({
|
|
|
|
|
"width": "100%"
|
|
|
|
|
});
|
2015-07-31 13:56:33 +08:00
|
|
|
|
video.append(svg);
|
2015-11-18 23:01:22 +08:00
|
|
|
|
svg.css({
|
|
|
|
|
"position": "absolute",
|
|
|
|
|
"top": 0,
|
|
|
|
|
"left": 0
|
|
|
|
|
});
|
2015-07-31 13:56:33 +08:00
|
|
|
|
var playBox = _playBox(svg);
|
|
|
|
|
svg.addChild(playBox);
|
2015-11-18 23:01:22 +08:00
|
|
|
|
playBox.addEventListener("click", function(e) {
|
2015-07-31 13:56:33 +08:00
|
|
|
|
var m = $(this),
|
|
|
|
|
video = m.parent().parent().find("video");
|
|
|
|
|
var bool = m.attr("play");
|
|
|
|
|
if (bool) {
|
|
|
|
|
this.setTimeout = null;
|
|
|
|
|
video[0].pause();
|
|
|
|
|
m.removeAttr("play")
|
|
|
|
|
} else {
|
2015-11-18 23:01:22 +08:00
|
|
|
|
this.setTimeout = setTimeout(function() {
|
2015-07-31 13:56:33 +08:00
|
|
|
|
video[0].play();
|
|
|
|
|
}, 500);
|
|
|
|
|
|
|
|
|
|
m.attr("play", "true")
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
2015-09-16 15:33:14 +08:00
|
|
|
|
window.Motion.motionVideo = motionVideo;
|
2015-07-29 18:28:35 +08:00
|
|
|
|
});
|