这两个特效代码都是我找了很久才找到的,但是我没有本地保存代码的习惯,而项目里也暂时不用,所以为了避免遗失,我还是贴到这里吧。
背景彩带:
(function (name, factory) {
if (typeof window === "object") {
window[name] = factory();
}
})("Ribbons", function () {
var _w = window, _b = document.body, _d = document.documentElement;
var random = function () {
if (arguments.length === 1) {
if (Array.isArray(arguments[0])) {
var index = Math.round(random(0, arguments[0].length - 1));
return arguments[0][index];
}
return random(0, arguments[0]);
} else if (arguments.length === 2) {
return Math.random() * (arguments[1] - arguments[0]) + arguments[0];
}
return 0;
};
var screenInfo = function (e) {
var width = Math.max(0, _w.innerWidth || _d.clientWidth || _b.clientWidth || 0),
height = Math.max(0, _w.innerHeight || _d.clientHeight || _b.clientHeight || 0),
scrollx = Math.max(0, _w.pageXOffset || _d.scrollLeft || _b.scrollLeft || 0) - (_d.clientLeft || 0),
scrolly = Math.max(0, _w.pageYOffset || _d.scrollTop || _b.scrollTop || 0) - (_d.clientTop || 0);
return {
width: width,
height: height,
ratio: width / height,
centerx: width / 2,
centery: height / 2,
scrollx: scrollx,
scrolly: scrolly
};
};
var mouseInfo = function (e) {
var screen = screenInfo(e), mousex = e ? Math.max(0, e.pageX || e.clientX || 0) : 0,
mousey = e ? Math.max(0, e.pageY || e.clientY || 0) : 0;
return {
mousex: mousex,
mousey: mousey,
centerx: mousex - screen.width / 2,
centery: mousey - screen.height / 2
};
};
var Point = function (x, y) {
this.x = 0;
this.y = 0;
this.set(x, y);
};
Point.prototype = {
constructor: Point, set: function (x, y) {
this.x = x || 0;
this.y = y || 0;
}, copy: function (point) {
this.x = point.x || 0;
this.y = point.y || 0;
return this;
}, multiply: function (x, y) {
this.x *= x || 1;
this.y *= y || 1;
return this;
}, divide: function (x, y) {
this.x /= x || 1;
this.y /= y || 1;
return this;
}, add: function (x, y) {
this.x += x || 0;
this.y += y || 0;
return this;
}, subtract: function (x, y) {
this.x -= x || 0;
this.y -= y || 0;
return this;
}, clampX: function (min, max) {
this.x = Math.max(min, Math.min(this.x, max));
return this;
}, clampY: function (min, max) {
this.y = Math.max(min, Math.min(this.y, max));
return this;
}, flipX: function () {
this.x *= -1;
return

最低0.47元/天 解锁文章
1万+

被折叠的 条评论
为什么被折叠?



