Lookinfres
var titleTime,originTitle=document.title;document.addEventListener("visibilitychange",function(){document.hidden?(document.title="[闷声发大财中...] "+originTitle,clearTimeout(titleTime)):(document.title="[+1s] "+originTitle,titleTime=setTimeout(function(){document.title=originTitle},2e3))});
(function (window, document) {
window.requestAnimationFrame = (function () {
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function (callback) {
setTimeout(callback, 1000 / 60);
}
})();
function init() {
addMenuEvent();
}
init();
function addMenuEvent() {
var menu = document.getElementById('menu-main-post');
if (menu) {
var toc = document.getElementById('toc');
menu.title = toc ? '目录' : '回到顶部';
menu.onclick = function () {
if (toc) {
if (toc.style.display == 'block') {
toc.style.display = 'none';
} else {
toc.style.display = 'block';
}
} else {
returnTop();
}
};
}
}
var timer = null;
function returnTop() {
cancelAnimationFrame(timer);
timer = requestAnimationFrame(function fn() {
var oTop = document.body.scrollTop || document.documentElement.scrollTop;
if (oTop > 0) {
document.body.scrollTop = document.documentElement.scrollTop = oTop - 50;
timer = requestAnimationFrame(fn);
} else {
cancelAnimationFrame(timer);
}
});
}
})(window, document);
一键复制
编辑
Web IDE
原始数据
按行查看
历史