mirror of
https://github.com/jerryc127/hexo-theme-butterfly.git
synced 2026-04-16 17:50:54 +08:00
Breaking Change
1. 不再支持hexo 4.0.0以下版本 2. 添加hexo fragment_cache,加快生成速度 3. 完善V5圖標顯示,不再需要同時加載V4和v5圖標 4. 去除cheerio依賴 5. 整合豆瓣配置,增加配置遊戲,圖書頁面top_img,可設置是否設置meta,解決部分瀏覽器無法顯示圖片問題 6. 友情鏈接除列表外可自定義內容 7. 可設置主頁標題距離頂部距離 8. 側邊欄可隱藏,可設置手機頁面是否隱藏 9. 增加disqusjs和utterances 兩個評論 10. 主頁文章增加tags和更新日期顯示,可以配置post_meta 11. 首頁subtitle可關閉打字效果,可設置打字效果顯示一次或loop 12. 增加valine和gitalk的配置 13. darkmode配置整理 14. 增加404頁面 15. post_beautify改為beautify,頁面美化不再只限於post頁,page頁也一樣 16. 可設置是否顯示cover,可設置各位置的cover顯示 17. 增加mermaid,可畫流程圖、狀態圖、時序圖、甘特圖等等 18. 增加pangu配置,中英文之間添加空格 19. 整合部分配置 20. post-copyright增加decode網址 (可以顯示中文) 21. 增加部分顏色配置 Feature 1. 適配IE 2. 增加一個Tag Plugins: 圖庫集 3. 增加一個Tag Plugins: tag-hide 功能 inline/block 4. 去除page頁開頭顯示與標題一樣的內容 5. aside 公告欄設置,支持html代碼 6. 手機界面sidebar顯示進度條和加深對應的標題 7. 主頁subtitle 的 hitokoto 顯示內容出處 9. footer 的hexo鏈接改為https 10. 修改手機下,menus和toc的打開效果 11. 手機頁面下,搜索界面全屏顯示 12. SEO優化,標題欄改為h1顯示 13. 閲讀模式優化,可根據light mode 和darkmode調整背景 14. 當屏蔽js時,header會出現(之前用js控制,會隱藏) Fixed 1. 修復Tencent Analytics的script加載為https #105 2. 修復相關文章,日期顯示錯誤bug 3. 修復gitalk報錯問題 4. 修復當valine background 是絕對地址時無法顯示的bug 5. 修復medium-zoom 無法使用的bug 6. 修復在safari下,點擊或移動到首頁文章cover,圓角變成正方形的bug #114 7. 修復在部分瀏覽器下,aside,友情鏈接頭像轉動變形的bug 8. 修復在寬度限制下,表格內容溢出屏幕外而出現滾動條的bug \#138 9. 修復gitalk js 在一些沒有設置評論的page里加載的bug 10. 修復tag plugins 的gist 在不同主題下的背景顏色問題(黑色主題下,文字不易觀看) 11. 修復highlight figcaption 顯示不全的bug 12. 修復disqus評論數無法獲取的bug 13. 修復子目錄在觸摸屏下點擊,偶爾不出現的bug 14. 修復a標籤太長(連續英文字母)不會換行的bug 15. 修復toc滾動時,閲讀進度條也跟著滾動的bug 16. 修復aside的圖片,可點擊顯示大圖bug 17. 修復activate-power-mode設置參數無效bug 18. 修復語言上的錯誤 \#156 19. 修復主頁在safari桌面端,首頁滾動卡頓的bug
This commit is contained in:
334
source/js/third-party/piao.js
vendored
Normal file
334
source/js/third-party/piao.js
vendored
Normal file
@@ -0,0 +1,334 @@
|
||||
|
||||
(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 this
|
||||
},
|
||||
flipY: function () {
|
||||
this.y *= -1;
|
||||
return this
|
||||
}
|
||||
};
|
||||
var Factory = function (options) {
|
||||
this._canvas = null;
|
||||
this._context = null;
|
||||
this._sto = null;
|
||||
this._width = 0;
|
||||
this._height = 0;
|
||||
this._scroll = 0;
|
||||
this._ribbons = [];
|
||||
this._options = {
|
||||
colorSaturation: "80%",
|
||||
colorBrightness: "60%",
|
||||
colorAlpha: 0.65,
|
||||
colorCycleSpeed: 6,
|
||||
verticalPosition: "center",
|
||||
horizontalSpeed: 150,
|
||||
ribbonCount: 5,
|
||||
strokeSize: 5,
|
||||
parallaxAmount: -0.5,
|
||||
animateSections: true
|
||||
};
|
||||
this._onDraw = this._onDraw.bind(this);
|
||||
this._onResize = this._onResize.bind(this);
|
||||
this._onScroll = this._onScroll.bind(this);
|
||||
this.setOptions(options);
|
||||
this.init()
|
||||
};
|
||||
Factory.prototype = {
|
||||
constructor: Factory,
|
||||
setOptions: function (options) {
|
||||
if (typeof options === "object") {
|
||||
for (var key in options) {
|
||||
if (options.hasOwnProperty(key)) {
|
||||
this._options[key] = options[key]
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
init: function () {
|
||||
try {
|
||||
this._canvas = document.createElement("canvas");
|
||||
this._canvas.style["display"] = "block";
|
||||
this._canvas.style["position"] = "fixed";
|
||||
this._canvas.style["margin"] = "0";
|
||||
this._canvas.style["padding"] = "0";
|
||||
this._canvas.style["border"] = "0";
|
||||
this._canvas.style["outline"] = "0";
|
||||
this._canvas.style["left"] = "0";
|
||||
this._canvas.style["top"] = "0";
|
||||
this._canvas.style["width"] = "100%";
|
||||
this._canvas.style["height"] = "100%";
|
||||
this._canvas.style["z-index"] = "-1";
|
||||
this._onResize();
|
||||
this._context = this._canvas.getContext("2d");
|
||||
this._context.clearRect(0, 0, this._width, this._height);
|
||||
this._context.globalAlpha = this._options.colorAlpha;
|
||||
window.addEventListener("resize", this._onResize);
|
||||
window.addEventListener("scroll", this._onScroll);
|
||||
document.body.appendChild(this._canvas)
|
||||
} catch (e) {
|
||||
console.warn("Canvas Context Error: " + e.toString());
|
||||
return
|
||||
}
|
||||
this._onDraw()
|
||||
},
|
||||
addRibbon: function () {
|
||||
var dir = Math.round(random(1, 9)) > 5 ? "right" : "left",
|
||||
stop = 1000,
|
||||
hide = 200,
|
||||
min = 0 - hide,
|
||||
max = this._width + hide,
|
||||
movex = 0,
|
||||
movey = 0,
|
||||
startx = dir === "right" ? min : max,
|
||||
starty = Math.round(random(0, this._height));
|
||||
if (/^(top|min)$/i.test(this._options.verticalPosition)) {
|
||||
starty = 0 + hide
|
||||
} else if (/^(middle|center)$/i.test(this._options.verticalPosition)) {
|
||||
starty = this._height / 2
|
||||
} else if (/^(bottom|max)$/i.test(this._options.verticalPosition)) {
|
||||
starty = this._height - hide
|
||||
}
|
||||
var ribbon = [],
|
||||
point1 = new Point(startx, starty),
|
||||
point2 = new Point(startx, starty),
|
||||
point3 = null,
|
||||
color = Math.round(random(0, 360)),
|
||||
delay = 0;
|
||||
while (true) {
|
||||
if (stop <= 0) break;
|
||||
stop--;
|
||||
movex = Math.round((Math.random() * 1 - 0.2) * this._options.horizontalSpeed);
|
||||
movey = Math.round((Math.random() * 1 - 0.5) * (this._height * 0.25));
|
||||
point3 = new Point();
|
||||
point3.copy(point2);
|
||||
if (dir === "right") {
|
||||
point3.add(movex, movey);
|
||||
if (point2.x >= max) break
|
||||
} else if (dir === "left") {
|
||||
point3.subtract(movex, movey);
|
||||
if (point2.x <= min) break
|
||||
}
|
||||
ribbon.push({
|
||||
point1: new Point(point1.x, point1.y),
|
||||
point2: new Point(point2.x, point2.y),
|
||||
point3: point3,
|
||||
color: color,
|
||||
delay: delay,
|
||||
dir: dir,
|
||||
alpha: 0,
|
||||
phase: 0
|
||||
});
|
||||
point1.copy(point2);
|
||||
point2.copy(point3);
|
||||
delay += 4;
|
||||
color += this._options.colorCycleSpeed
|
||||
}
|
||||
this._ribbons.push(ribbon)
|
||||
},
|
||||
_drawRibbonSection: function (section) {
|
||||
if (section) {
|
||||
if (section.phase >= 1 && section.alpha <= 0) {
|
||||
return true
|
||||
}
|
||||
if (section.delay <= 0) {
|
||||
section.phase += 0.02;
|
||||
section.alpha = Math.sin(section.phase) * 1;
|
||||
section.alpha = section.alpha <= 0 ? 0 : section.alpha;
|
||||
section.alpha = section.alpha >= 1 ? 1 : section.alpha;
|
||||
if (this._options.animateSections) {
|
||||
var mod = Math.sin(1 + section.phase * Math.PI / 2) * 0.1;
|
||||
if (section.dir === "right") {
|
||||
section.point1.add(mod, 0);
|
||||
section.point2.add(mod, 0);
|
||||
section.point3.add(mod, 0)
|
||||
} else {
|
||||
section.point1.subtract(mod, 0);
|
||||
section.point2.subtract(mod, 0);
|
||||
section.point3.subtract(mod, 0)
|
||||
}
|
||||
section.point1.add(0, mod);
|
||||
section.point2.add(0, mod);
|
||||
section.point3.add(0, mod)
|
||||
}
|
||||
} else {
|
||||
section.delay -= 0.5
|
||||
}
|
||||
var s = this._options.colorSaturation,
|
||||
l = this._options.colorBrightness,
|
||||
c = "hsla(" + section.color + ", " + s + ", " + l + ", " + section.alpha + " )";
|
||||
this._context.save();
|
||||
if (this._options.parallaxAmount !== 0) {
|
||||
this._context.translate(0, this._scroll * this._options.parallaxAmount)
|
||||
}
|
||||
this._context.beginPath();
|
||||
this._context.moveTo(section.point1.x, section.point1.y);
|
||||
this._context.lineTo(section.point2.x, section.point2.y);
|
||||
this._context.lineTo(section.point3.x, section.point3.y);
|
||||
this._context.fillStyle = c;
|
||||
this._context.fill();
|
||||
if (this._options.strokeSize > 0) {
|
||||
this._context.lineWidth = this._options.strokeSize;
|
||||
this._context.strokeStyle = c;
|
||||
this._context.lineCap = "round";
|
||||
this._context.stroke()
|
||||
}
|
||||
this._context.restore()
|
||||
}
|
||||
return false
|
||||
},
|
||||
_onDraw: function () {
|
||||
for (var i = 0, t = this._ribbons.length; i < t; ++i) {
|
||||
if (!this._ribbons[i]) {
|
||||
this._ribbons.splice(i, 1)
|
||||
}
|
||||
}
|
||||
this._context.clearRect(0, 0, this._width, this._height);
|
||||
for (var a = 0; a < this._ribbons.length; ++a) {
|
||||
var ribbon = this._ribbons[a],
|
||||
numSections = ribbon.length,
|
||||
numDone = 0;
|
||||
for (var b = 0; b < numSections; ++b) {
|
||||
if (this._drawRibbonSection(ribbon[b])) {
|
||||
numDone++
|
||||
}
|
||||
}
|
||||
if (numDone >= numSections) {
|
||||
this._ribbons[a] = null
|
||||
}
|
||||
}
|
||||
if (this._ribbons.length < this._options.ribbonCount) {
|
||||
this.addRibbon()
|
||||
}
|
||||
requestAnimationFrame(this._onDraw)
|
||||
},
|
||||
_onResize: function (e) {
|
||||
var screen = screenInfo(e);
|
||||
this._width = screen.width;
|
||||
this._height = screen.height;
|
||||
if (this._canvas) {
|
||||
this._canvas.width = this._width;
|
||||
this._canvas.height = this._height;
|
||||
if (this._context) {
|
||||
this._context.globalAlpha = this._options.colorAlpha
|
||||
}
|
||||
}
|
||||
},
|
||||
_onScroll: function (e) {
|
||||
var screen = screenInfo(e);
|
||||
this._scroll = screen.scrolly
|
||||
}
|
||||
};
|
||||
return Factory
|
||||
});
|
||||
|
||||
var cn = document.getElementById('ribbon_piao');
|
||||
var mb = cn.getAttribute("mobile");
|
||||
|
||||
if ( mb == 'false' && (/Android|webOS|iPhone|iPod|iPad|BlackBerry/i.test(navigator.userAgent))) {
|
||||
|
||||
} else {
|
||||
new Ribbons({
|
||||
colorSaturation: "60%",
|
||||
colorBrightness: "50%",
|
||||
colorAlpha: 0.5,
|
||||
colorCycleSpeed: 5,
|
||||
verticalPosition: "random",
|
||||
horizontalSpeed: 200,
|
||||
ribbonCount: 3,
|
||||
strokeSize: 0,
|
||||
parallaxAmount: -0.2,
|
||||
animateSections: true
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user