Skip to content

Commit 1afceb7

Browse files
committed
Site updated: 2016-10-03 21:26:59
1 parent 28e0b69 commit 1afceb7

File tree

21 files changed

+2155
-232
lines changed

21 files changed

+2155
-232
lines changed

1.1.js

Lines changed: 221 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
webpackJsonp([1],{
22

33
/***/ 22:
4-
/***/ function(module, exports) {
4+
/***/ function(module, exports, __webpack_require__) {
55

6-
/**
6+
var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;/**
77
* @author littenli
88
* @date 2014-03-10 version 0.2
99
* @description 图片延时加载,裂图替换,图片错误上报处理
@@ -14,9 +14,228 @@ webpackJsonp([1],{
1414
* options.errCallBack {Function} 可为空.提供img加载失败回调,供业务额外去处理加载失败逻辑
1515
* options.container {Dom} 提供容器节点内可视区域的加载能力,默认为window
1616
*/
17+
! function(t, e) {
18+
function r(r) {
19+
if ("undefined" == typeof r) throw new Error('Pathformer [constructor]: "element" parameter is required');
20+
if (r.constructor === String && (r = e.getElementById(r), !r)) throw new Error('Pathformer [constructor]: "element" parameter is not related to an existing ID');
21+
if (!(r.constructor instanceof t.SVGElement || /^svg$/i.test(r.nodeName))) throw new Error('Pathformer [constructor]: "element" parameter must be a string or a SVGelement');
22+
this.el = r, this.scan(r)
23+
}
1724

25+
function n(t, e, r) {
26+
this.isReady = !1, this.setElement(t, e), this.setOptions(e), this.setCallback(r), this.isReady && this.init()
27+
}
28+
r.prototype.TYPES = ["line", "elipse", "circle", "polygon", "polyline", "rect"], r.prototype.ATTR_WATCH = ["cx", "cy", "points", "r", "rx", "ry", "x", "x1", "x2", "y", "y1", "y2"], r.prototype.scan = function(t) {
29+
for (var e, r, n, i, a = t.querySelectorAll(this.TYPES.join(",")), o = 0; o < a.length; o++) r = a[o], e = this[r.tagName.toLowerCase() + "ToPath"], n = e(this.parseAttr(r.attributes)), i = this.pathMaker(r, n), r.parentNode.replaceChild(i, r)
30+
}, r.prototype.lineToPath = function(t) {
31+
var e = {};
32+
return e.d = "M" + t.x1 + "," + t.y1 + "L" + t.x2 + "," + t.y2, e
33+
}, r.prototype.rectToPath = function(t) {
34+
var e = {},
35+
r = parseFloat(t.x) || 0,
36+
n = parseFloat(t.y) || 0,
37+
i = parseFloat(t.width) || 0,
38+
a = parseFloat(t.height) || 0;
39+
return e.d = "M" + r + " " + n + " ", e.d += "L" + (r + i) + " " + n + " ", e.d += "L" + (r + i) + " " + (n + a) + " ", e.d += "L" + r + " " + (n + a) + " Z", e
40+
}, r.prototype.polylineToPath = function(t) {
41+
var e, r, n = {},
42+
i = t.points.split(" ");
43+
if (-1 === t.points.indexOf(",")) {
44+
var a = [];
45+
for (e = 0; e < i.length; e += 2) a.push(i[e] + "," + i[e + 1]);
46+
i = a
47+
}
48+
for (r = "M" + i[0], e = 1; e < i.length; e++) - 1 !== i[e].indexOf(",") && (r += "L" + i[e]);
49+
return n.d = r, n
50+
}, r.prototype.polygonToPath = function(t) {
51+
var e = r.prototype.polylineToPath(t);
52+
return e.d += "Z", e
53+
}, r.prototype.elipseToPath = function(t) {
54+
var e = t.cx - t.rx,
55+
r = t.cy,
56+
n = parseFloat(t.cx) + parseFloat(t.rx),
57+
i = t.cy,
58+
a = {};
59+
return a.d = "M" + e + "," + r + "A" + t.rx + "," + t.ry + " 0,1,1 " + n + "," + i + "A" + t.rx + "," + t.ry + " 0,1,1 " + e + "," + i, a
60+
}, r.prototype.circleToPath = function(t) {
61+
var e = {},
62+
r = t.cx - t.r,
63+
n = t.cy,
64+
i = parseFloat(t.cx) + parseFloat(t.r),
65+
a = t.cy;
66+
return e.d = "M" + r + "," + n + "A" + t.r + "," + t.r + " 0,1,1 " + i + "," + a + "A" + t.r + "," + t.r + " 0,1,1 " + r + "," + a, e
67+
}, r.prototype.pathMaker = function(t, r) {
68+
var n, i, a = e.createElementNS("http://www.w3.org/2000/svg", "path");
69+
for (n = 0; n < t.attributes.length; n++) i = t.attributes[n], -1 === this.ATTR_WATCH.indexOf(i.name) && a.setAttribute(i.name, i.value);
70+
for (n in r) a.setAttribute(n, r[n]);
71+
return a
72+
}, r.prototype.parseAttr = function(t) {
73+
for (var e, r = {}, n = 0; n < t.length; n++) {
74+
if (e = t[n], -1 !== this.ATTR_WATCH.indexOf(e.name) && -1 !== e.value.indexOf("%")) throw new Error("Pathformer [parseAttr]: a SVG shape got values in percentage. This cannot be transformed into 'path' tags. Please use 'viewBox'.");
75+
r[e.name] = e.value
76+
}
77+
return r
78+
};
79+
var i, a, o;
80+
n.LINEAR = function(t) {
81+
return t
82+
}, n.EASE = function(t) {
83+
return -Math.cos(t * Math.PI) / 2 + .5
84+
}, n.EASE_OUT = function(t) {
85+
return 1 - Math.pow(1 - t, 3)
86+
}, n.EASE_IN = function(t) {
87+
return Math.pow(t, 3)
88+
}, n.EASE_OUT_BOUNCE = function(t) {
89+
var e = -Math.cos(.5 * t * Math.PI) + 1,
90+
r = Math.pow(e, 1.5),
91+
n = Math.pow(1 - t, 2),
92+
i = -Math.abs(Math.cos(2.5 * r * Math.PI)) + 1;
93+
return 1 - n + i * n
94+
}, n.prototype.setElement = function(r, n) {
95+
if ("undefined" == typeof r) throw new Error('Vivus [constructor]: "element" parameter is required');
96+
if (r.constructor === String && (r = e.getElementById(r), !r)) throw new Error('Vivus [constructor]: "element" parameter is not related to an existing ID');
97+
if (n && n.file) {
98+
var i = e.createElement("object");
99+
i.setAttribute("type", "image/svg+xml"), i.setAttribute("data", n.file), r.appendChild(i), r = i
100+
}
101+
switch (r.constructor) {
102+
case t.SVGSVGElement:
103+
case t.SVGElement:
104+
this.el = r, this.isReady = !0;
105+
break;
106+
case t.HTMLObjectElement:
107+
if (this.el = r.contentDocument && r.contentDocument.querySelector("svg"), this.el) return this.isReady = !0, void 0;
108+
var a = this;
109+
r.addEventListener("load", function() {
110+
if (a.el = r.contentDocument && r.contentDocument.querySelector("svg"), !a.el) throw new Error("Vivus [constructor]: object loaded does not contain any SVG");
111+
a.isReady = !0, a.init()
112+
});
113+
break;
114+
default:
115+
throw new Error('Vivus [constructor]: "element" parameter is not valid (or miss the "file" attribute)')
116+
}
117+
}, n.prototype.setOptions = function(e) {
118+
var r = ["delayed", "async", "oneByOne", "scenario", "scenario-sync"],
119+
i = ["inViewport", "manual", "autostart"];
120+
if (void 0 !== e && e.constructor !== Object) throw new Error('Vivus [constructor]: "options" parameter must be an object');
121+
if (e = e || {}, e.type && -1 === r.indexOf(e.type)) throw new Error("Vivus [constructor]: " + e.type + " is not an existing animation `type`");
122+
if (this.type = e.type || r[0], e.start && -1 === i.indexOf(e.start)) throw new Error("Vivus [constructor]: " + e.start + " is not an existing `start` option");
123+
if (this.start = e.start || i[0], this.isIE = -1 !== t.navigator.userAgent.indexOf("MSIE"), this.duration = o(e.duration, 120), this.delay = o(e.delay, null), this.dashGap = o(e.dashGap, 2), this.forceRender = e.hasOwnProperty("forceRender") ? !!e.forceRender : this.isIE, this.selfDestroy = !!e.selfDestroy, this.onReady = e.onReady, this.animTimingFunction = e.animTimingFunction || n.LINEAR, this.pathTimingFunction = e.pathTimingFunction || n.LINEAR, this.delay >= this.duration) throw new Error("Vivus [constructor]: delay must be shorter than duration")
124+
}, n.prototype.setCallback = function(t) {
125+
if (t && t.constructor !== Function) throw new Error('Vivus [constructor]: "callback" parameter must be a function');
126+
this.callback = t || function() {}
127+
}, n.prototype.mapping = function() {
128+
var e, r, n, i, a, s, h, c;
129+
for (c = s = h = 0, r = this.el.querySelectorAll("path"), e = 0; e < r.length; e++) n = r[e], a = {
130+
el: n,
131+
length: Math.ceil(n.getTotalLength())
132+
}, isNaN(a.length) ? t.console && console.warn && console.warn("Vivus [mapping]: cannot retrieve a path element length", n) : (s += a.length, this.map.push(a), n.style.strokeDasharray = a.length + " " + (a.length + this.dashGap), n.style.strokeDashoffset = a.length, this.isIE && (a.length += this.dashGap), this.renderPath(e));
133+
for (s = 0 === s ? 1 : s, this.delay = null === this.delay ? this.duration / 3 : this.delay, this.delayUnit = this.delay / (r.length > 1 ? r.length - 1 : 1), e = 0; e < this.map.length; e++) {
134+
switch (a = this.map[e], this.type) {
135+
case "delayed":
136+
a.startAt = this.delayUnit * e, a.duration = this.duration - this.delay;
137+
break;
138+
case "oneByOne":
139+
a.startAt = h / s * this.duration, a.duration = a.length / s * this.duration;
140+
break;
141+
case "async":
142+
a.startAt = 0, a.duration = this.duration;
143+
break;
144+
case "scenario-sync":
145+
n = r[e], i = this.parseAttr(n), a.startAt = c + (o(i["data-delay"], this.delayUnit) || 0), a.duration = o(i["data-duration"], this.duration), c = void 0 !== i["data-async"] ? a.startAt : a.startAt + a.duration, this.frameLength = Math.max(this.frameLength, a.startAt + a.duration);
146+
break;
147+
case "scenario":
148+
n = r[e], i = this.parseAttr(n), a.startAt = o(i["data-start"], this.delayUnit) || 0, a.duration = o(i["data-duration"], this.duration), this.frameLength = Math.max(this.frameLength, a.startAt + a.duration)
149+
}
150+
h += a.length, this.frameLength = this.frameLength || this.duration
151+
}
152+
}, n.prototype.drawer = function() {
153+
var t = this;
154+
this.currentFrame += this.speed, this.currentFrame <= 0 ? (this.stop(), this.reset(), this.callback(this)) : this.currentFrame >= this.frameLength ? (this.stop(), this.currentFrame = this.frameLength, this.trace(), this.selfDestroy && this.destroy(), this.callback(this)) : (this.trace(), this.handle = i(function() {
155+
t.drawer()
156+
}))
157+
}, n.prototype.trace = function() {
158+
var t, e, r, n;
159+
for (n = this.animTimingFunction(this.currentFrame / this.frameLength) * this.frameLength, t = 0; t < this.map.length; t++) r = this.map[t], e = (n - r.startAt) / r.duration, e = this.pathTimingFunction(Math.max(0, Math.min(1, e))), r.progress !== e && (r.progress = e, r.el.style.strokeDashoffset = Math.floor(r.length * (1 - e)), this.renderPath(t))
160+
}, n.prototype.renderPath = function(t) {
161+
if (this.forceRender && this.map && this.map[t]) {
162+
var e = this.map[t],
163+
r = e.el.cloneNode(!0);
164+
e.el.parentNode.replaceChild(r, e.el), e.el = r
165+
}
166+
}, n.prototype.init = function() {
167+
this.frameLength = 0, this.currentFrame = 0, this.map = [], new r(this.el), this.mapping(), this.starter(), this.onReady && this.onReady(this)
168+
}, n.prototype.starter = function() {
169+
switch (this.start) {
170+
case "manual":
171+
return;
172+
case "autostart":
173+
this.play();
174+
break;
175+
case "inViewport":
176+
var e = this,
177+
r = function() {
178+
e.isInViewport(e.el, 1) && (e.play(), t.removeEventListener("scroll", r))
179+
};
180+
t.addEventListener("scroll", r), r()
181+
}
182+
}, n.prototype.getStatus = function() {
183+
return 0 === this.currentFrame ? "start" : this.currentFrame === this.frameLength ? "end" : "progress"
184+
}, n.prototype.reset = function() {
185+
return this.setFrameProgress(0)
186+
}, n.prototype.finish = function() {
187+
return this.setFrameProgress(1)
188+
}, n.prototype.setFrameProgress = function(t) {
189+
return t = Math.min(1, Math.max(0, t)), this.currentFrame = Math.round(this.frameLength * t), this.trace(), this
190+
}, n.prototype.play = function(t) {
191+
if (t && "number" != typeof t) throw new Error("Vivus [play]: invalid speed");
192+
return this.speed = t || 1, this.handle || this.drawer(), this
193+
}, n.prototype.stop = function() {
194+
return this.handle && (a(this.handle), delete this.handle), this
195+
}, n.prototype.destroy = function() {
196+
var t, e;
197+
for (t = 0; t < this.map.length; t++) e = this.map[t], e.el.style.strokeDashoffset = null, e.el.style.strokeDasharray = null, this.renderPath(t)
198+
}, n.prototype.parseAttr = function(t) {
199+
var e, r = {};
200+
if (t && t.attributes)
201+
for (var n = 0; n < t.attributes.length; n++) e = t.attributes[n], r[e.name] = e.value;
202+
return r
203+
}, n.prototype.isInViewport = function(t, e) {
204+
var r = this.scrollY(),
205+
n = r + this.getViewportH(),
206+
i = t.getBoundingClientRect(),
207+
a = i.height,
208+
o = r + i.top,
209+
s = o + a;
210+
return e = e || 0, n >= o + a * e && s >= r
211+
}, n.prototype.docElem = t.document.documentElement, n.prototype.getViewportH = function() {
212+
var e = this.docElem.clientHeight,
213+
r = t.innerHeight;
214+
return r > e ? r : e
215+
}, n.prototype.scrollY = function() {
216+
return t.pageYOffset || this.docElem.scrollTop
217+
}, i = function() {
218+
return t.requestAnimationFrame || t.webkitRequestAnimationFrame || t.mozRequestAnimationFrame || t.oRequestAnimationFrame || t.msRequestAnimationFrame || function(e) {
219+
return t.setTimeout(e, 1e3 / 60)
220+
}
221+
}(), a = function() {
222+
return t.cancelAnimationFrame || t.webkitCancelAnimationFrame || t.mozCancelAnimationFrame || t.oCancelAnimationFrame || t.msCancelAnimationFrame || function(e) {
223+
return t.clearTimeout(e)
224+
}
225+
}(), o = function(t, e) {
226+
var r = parseInt(t, 10);
227+
return r >= 0 ? r : e
228+
}, true ? !(__WEBPACK_AMD_DEFINE_ARRAY__ = [], __WEBPACK_AMD_DEFINE_RESULT__ = function() {
229+
return n
230+
}.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)) : "object" == typeof exports ? module.exports = n : t.Vivus = n
231+
}(window, document);
18232

19233
$.fn.lazyload = function(options) {
234+
new Vivus("vkki-logo", {
235+
type: "delayed",
236+
duration: 200,
237+
animTimingFunction: Vivus.EASE_OUT
238+
});
20239
return this.each(function() {
21240

22241
options = options || {};

2.2.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,13 @@ webpackJsonp([2],{
1515
* options.container {Dom} 提供容器节点内可视区域的加载能力,默认为window
1616
*/
1717

18-
1918
$.fn.lazyload = function(options) {
19+
lazySG();
20+
new Vivus("vkki-logo", {
21+
type: "delayed",
22+
duration: 200,
23+
animTimingFunction: Vivus.EASE_OUT
24+
});
2025
return this.each(function() {
2126

2227
options = options || {};

0 commit comments

Comments
 (0)