4
4
Free for personal and commercial use under the CCA 3.0 license (html5up.net/license)
5
5
*/
6
6
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
+
7
18
( function ( $ ) {
8
19
9
20
var $window = $ ( window ) ,
@@ -320,4 +331,92 @@ var a = 0;
320
331
$ ( '#fullscreen' ) . on ( 'click' , function ( ) {
321
332
a ++ ;
322
333
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
+ } ) ;
0 commit comments