Skip to content

Commit d33e7e7

Browse files
committed
性能改进
1 parent 9f203de commit d33e7e7

File tree

6 files changed

+112
-5
lines changed

6 files changed

+112
-5
lines changed

assets/js/main.js

Lines changed: 100 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,17 @@
44
Free for personal and commercial use under the CCA 3.0 license (html5up.net/license)
55
*/
66

7+
jQuery.event.special.touchstart = {
8+
setup: function( _, ns, handle ) {
9+
this.addEventListener("touchstart", handle, { passive: true });
10+
}
11+
};
12+
jQuery.event.special.touchmove = {
13+
setup: function( _, ns, handle ) {
14+
this.addEventListener("touchmove", handle, { passive: true });
15+
}
16+
};
17+
718
(function($) {
819

920
var $window = $(window),
@@ -320,4 +331,92 @@ var a = 0;
320331
$('#fullscreen').on('click', function() {
321332
a++;
322333
a % 2 == 1 ? enterfullscreen() : exitfullscreen();
323-
})
334+
})
335+
336+
$(function() {
337+
var loading = false;
338+
var $loadMore = $('#load-more');
339+
var currentPage = 1;
340+
var $main = $('#main');
341+
var totalPages = parseInt($loadMore.data('total-pages')); // 获取总页数
342+
343+
var scrollHandler = function() {
344+
// 如果正在加载或者没有更多内容,则不执行
345+
if(loading) return;
346+
347+
// 如果已经到达最后一页,则移除加载更多标记并返回
348+
if(currentPage >= totalPages) {
349+
$loadMore.remove();
350+
return;
351+
}
352+
353+
// 检查是否滚动到底部
354+
if($(window).scrollTop() + $(window).height() > $loadMore.offset().top - 100) {
355+
loading = true;
356+
currentPage++;
357+
358+
// 发起 AJAX 请求加载下一页
359+
$.ajax({
360+
url: window.location.pathname,
361+
type: 'GET',
362+
data: {
363+
page: currentPage
364+
},
365+
success: function(response) {
366+
// 解析返回的 HTML
367+
var $res = $(response);
368+
var $newPosts = $res.find('.thumb.img-area');
369+
370+
// 如果没有新文章了,则移除加载更多标记
371+
if($newPosts.length === 0) {
372+
$loadMore.remove();
373+
return;
374+
}
375+
376+
// 将新文章插入到容器中
377+
$newPosts.insertBefore($loadMore);
378+
379+
// 重新初始化新加载文章的图片懒加载
380+
checkImgs();
381+
382+
// 重新初始化 Poptrox
383+
$main.poptrox({
384+
baseZIndex: 20000,
385+
caption: function($a) {
386+
var s = '';
387+
$a.nextAll().each(function() {
388+
s += this.outerHTML;
389+
});
390+
return s;
391+
},
392+
fadeSpeed: 300,
393+
onPopupClose: function() { $body.removeClass('modal-active'); },
394+
onPopupOpen: function() { $body.addClass('modal-active'); },
395+
overlayOpacity: 0,
396+
popupCloserText: '',
397+
popupHeight: 150,
398+
popupLoaderText: '',
399+
popupSpeed: 300,
400+
popupWidth: 150,
401+
selector: '.thumb > a.image',
402+
usePopupCaption: true,
403+
usePopupCloser: true,
404+
usePopupDefaultStyling: false,
405+
usePopupForceClose: true,
406+
usePopupLoader: true,
407+
usePopupNav: true,
408+
windowMargin: 50
409+
});
410+
411+
loading = false;
412+
},
413+
error: function() {
414+
loading = false;
415+
}
416+
});
417+
}
418+
};
419+
420+
// 使用 passive 选项添加滚动事件监听器
421+
window.addEventListener('scroll', scrollHandler, { passive: true });
422+
});

assets/js/util.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,4 +586,5 @@
586586

587587
})(jQuery);
588588

589-
document.write("<h1></h1>");
589+
// 使用DOM API添加元素
590+
document.body.appendChild(document.createElement('h1'));

assets/sass/main.scss

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
@import 'libs/vendor';
55
@import 'libs/breakpoints';
66
@import 'fontawesome-all.min.css';
7-
@import url('https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,300italic,400,400italic');
87

98
/*
109
Multiverse by HTML5 UP

index.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* 一款简约的相册主题
44
* @package 洪墨时光
55
* @author zhheo
6-
* @version 2.12
6+
* @version 2.13
77
* @link https://zhheo.com/
88
*/
99
?>
@@ -102,6 +102,9 @@
102102
</li>
103103
</article>
104104
<?php endwhile; ?>
105+
106+
<!-- 添加一个加载更多的容器,并包含总页数信息 -->
107+
<div id="load-more" data-page="1" data-total-pages="<?php echo ceil($this->getTotal() / $this->parameter->pageSize); ?>"></div>
105108
</div>
106109

107110
<body>

releases.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"tag_name": "2.12"
2+
"tag_name": "2.13"
33
}

update.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ rsync -avz --progress --chmod=755 ./ root@116.196.68.153:/www/wwwroot/plog.zhheo
44

55
# 更新日志
66

7+
## 2.13
8+
性能提升:现在你无需设置每页展示999个文章了。现在只会按需加载
9+
移除了google字体请求
10+
大幅度优化了滚动性能
11+
712
## 2.12
813
添加主题中文名
914
移除被issues误导而添加的换行判断

0 commit comments

Comments
 (0)