perf: optimize

This commit is contained in:
Spirit 2020-04-11 23:08:16 +08:00
parent 6b919d0157
commit 85f010d6aa
2 changed files with 30 additions and 37 deletions

View File

@ -79,14 +79,21 @@ function post_list_show_animation() {
function callback(entries) { function callback(entries) {
entries.forEach((article) => { entries.forEach((article) => {
if (article.target.classList.contains("post-list-show")) { if (!window.IntersectionObserver) {
article.target.style.willChange = 'auto'; article.target.style.willChange = 'auto';
io.unobserve(article.target) if( article.target.classList.contains("post-list-show") === false){
} else {
if (article.isIntersecting) {
article.target.classList.add("post-list-show"); article.target.classList.add("post-list-show");
}
} else {
if (article.target.classList.contains("post-list-show")) {
article.target.style.willChange = 'auto'; article.target.style.willChange = 'auto';
io.unobserve(article.target) io.unobserve(article.target)
} else {
if (article.isIntersecting) {
article.target.classList.add("post-list-show");
article.target.style.willChange = 'auto';
io.unobserve(article.target)
}
} }
} }
}) })
@ -325,46 +332,26 @@ function checkBgImgCookie() {
function checkDarkModeCookie() { function checkDarkModeCookie() {
var dark = getCookie("dark"), var dark = getCookie("dark"),
today = new Date() today = new Date(),
cWidth = document.body.clientWidth; hour = today.getHours();
if (!dark) { if ((!dark && (hour > 21 || hour < 7) ) || (dark == '1' && (hour >= 22 || hour <= 6))) {
if ((today.getHours() > 21 || today.getHours() < 7)) {
setTimeout(function () { setTimeout(function () {
$("#dark-bg").click(); $("#dark-bg").click();
}, 100); }, 100);
$("#moblieDarkLight").html('<i class="fa fa-sun-o" aria-hidden="true"></i>');
console.log('夜间模式开启'); console.log('夜间模式开启');
} else { } else {
if (cWidth > 860) { if (document.body.clientWidth > 860) {
setTimeout(function () { setTimeout(function () {
checkBgImgCookie(); checkBgImgCookie();
}, 100); }, 100);
console.log('夜间模式关闭');
} else { } else {
$("html").css("background", "unset"); $("html").css("background", "unset");
$("body").removeClass("dark"); $("body").removeClass("dark");
$("#moblieDarkLight").html('<i class="fa fa-moon-o" aria-hidden="true"></i>'); $("#moblieDarkLight").html('<i class="fa fa-moon-o" aria-hidden="true"></i>');
setCookie("dark", "0", 0.33); setCookie("dark", "0", 0.33);
} }
} console.log('夜间模式关闭');
} else {
if (dark == '1' && (today.getHours() >= 22 || today.getHours() <= 6)) {
setTimeout(function () {
$("#dark-bg").click();
}, 100);
console.log('夜间模式开启');
} else if (dark == '0' || today.getHours() < 22 || today.getHours() > 6) {
if (cWidth > 860) {
setTimeout(function () {
checkBgImgCookie();
}, 100);
console.log('夜间模式关闭');
} else {
$("html").css("background", "unset");
$("body").removeClass("dark");
$("#moblieDarkLight").html('<i class="fa fa-moon-o" aria-hidden="true"></i>');
setCookie("dark", "0", 0.33);
}
}
} }
} }
if (!getCookie("darkcache") && (new Date().getHours() > 21 || new Date().getHours() < 7)) { if (!getCookie("darkcache") && (new Date().getHours() > 21 || new Date().getHours() < 7)) {
@ -497,12 +484,9 @@ $(document).ready(function () {
}); });
function topFunction() { function topFunction() {
window.scrollBy(0, -100) $('body,html').animate({
scrolldelay = setTimeout('topFunction()', 10) scrollTop: 0
var sTop = document.documentElement.scrollTop + document.body.scrollTop })
if (sTop === 0) {
clearTimeout(scrolldelay)
}
} }
function timeSeriesReload(flag) { function timeSeriesReload(flag) {

View File

@ -1709,6 +1709,10 @@ i.iconfont.hotpost {
background: #FBFBFB background: #FBFBFB
} }
body.dark .s-content{
background: unset;
}
.s-time i { .s-time i {
font-size: 13px; font-size: 13px;
margin-right: 5px margin-right: 5px
@ -5890,6 +5894,11 @@ i.iconfont.down {
background-color: #f1f1f1 background-color: #f1f1f1
} }
body.dark .user-menu-option a:hover {
color: #3daee9;
background-color: #232629
}
.no-logged { .no-logged {
font-size: 13px; font-size: 13px;
padding: 15px 10px; padding: 15px 10px;
@ -5899,7 +5908,7 @@ i.iconfont.down {
.no-logged a { .no-logged a {
display: initial; display: initial;
color: #69d2e7; color: #69d2e7 !important;
font-size: 14px; font-size: 14px;
padding: 0 5px; padding: 0 5px;
text-decoration: underline text-decoration: underline