11"use strict" ;
22$ ( function ( ) {
33 /* 目录 */
4- $ ( ".ni-sidenav-list" ) . on ( "click" , function ( e ) {
4+ $ ( ".ni-sidenav-list" ) . on ( "click" , function ( e ) {
55 let target = e . target ;
66 if ( target . tagName . toLowerCase ( ) == "a" ) {
77 e . preventDefault ( ) ;
88 e . stopPropagation ( ) ;
99 let hash = "#" + decodeURIComponent ( target . href . split ( "#" ) [ 1 ] ) ;
10- history . pushState ( {
11- "url" : location . href
12- } , hash , location . href . split ( "#" ) [ 0 ] + hash ) ;
13- $ ( "html" ) . animate ( {
14- scrollTop : $ ( hash ) . offset ( ) . top
15- } , 300 ) ;
10+ history . pushState (
11+ {
12+ "url" : location . href ,
13+ } ,
14+ hash ,
15+ location . href . split ( "#" ) [ 0 ] + hash
16+ ) ;
17+ $ ( "html" ) . animate (
18+ {
19+ scrollTop : $ ( hash ) . offset ( ) . top ,
20+ } ,
21+ 300
22+ ) ;
1623 }
1724 } ) ;
1825 $ ( "body" ) . scrollspy ( {
19- "target" : ".ni-sidenav"
26+ "target" : ".ni-sidenav" ,
2027 } ) ;
2128
2229 /* 返回页面顶端 */
23- $ ( ".ni-navtop" ) . on ( "click" , function ( e ) {
30+ $ ( ".ni-navtop" ) . on ( "click" , function ( e ) {
2431 e . preventDefault ( ) ;
25- $ ( "html" ) . animate ( {
26- scrollTop : 0
27- } , 500 ) ;
32+ $ ( "html" ) . animate (
33+ {
34+ scrollTop : 0 ,
35+ } ,
36+ 500
37+ ) ;
2838 } ) ;
29- $ ( ".ni-navbottom" ) . on ( "click" , function ( e ) {
39+ $ ( ".ni-navbottom" ) . on ( "click" , function ( e ) {
3040 e . preventDefault ( ) ;
31- $ ( "html" ) . animate ( {
32- scrollTop : $ ( document . body ) . height ( )
33- } , 500 ) ;
41+ $ ( "html" ) . animate (
42+ {
43+ scrollTop : $ ( document . body ) . height ( ) ,
44+ } ,
45+ 500
46+ ) ;
3447 } ) ;
3548
3649 /* resize */
3750 window . windowResize = function ( ) {
3851 let headerHeight = $ ( ".ni-header" ) . outerHeight ( ) ,
39- footerHeight = $ ( ".ni-footer" ) . outerHeight ( ) ;
52+ footerHeight = $ ( ".ni-footer" ) . outerHeight ( ) ;
4053 $ ( "body" ) . css ( {
41- "margin-bottom" : footerHeight + 30
54+ "margin-bottom" : footerHeight + 30 ,
4255 } ) ;
4356 $ ( ".ni-sidenav-list" ) . affix ( {
4457 "offset" : {
4558 "top" : $ ( ".ni-content-main" ) . offset ( ) . top ,
46- "bottom" : footerHeight
47- }
59+ "bottom" : footerHeight ,
60+ } ,
4861 } ) ;
4962 $ ( ".ni-search-content" ) . css ( {
5063 "top" : headerHeight ,
51- "height" : $ ( window ) . innerHeight ( ) - headerHeight
64+ "height" : $ ( window ) . innerHeight ( ) - headerHeight ,
5265 } ) ;
5366 } ;
5467 windowResize ( ) ;
@@ -57,14 +70,21 @@ $(function () {
5770 /* scroll */
5871 let scrollTimer ;
5972 window . windowScroll = function ( ) {
60- $ ( ".ni-footer-navtop" ) . css ( {
61- "bottom" : Math . max ( ( $ ( window ) . scrollTop ( ) + $ ( window ) . innerHeight ( ) ) - ( $ ( ".ni-content-main" ) . offset ( ) . top + $ ( ".ni-content-main" ) . outerHeight ( ) ) , 25 )
62- } ) . fadeIn ( 200 ) ;
73+ $ ( ".ni-footer-navtop" )
74+ . css ( {
75+ "bottom" : Math . max (
76+ $ ( window ) . scrollTop ( ) +
77+ $ ( window ) . innerHeight ( ) -
78+ ( $ ( ".ni-content-main" ) . offset ( ) . top + $ ( ".ni-content-main" ) . outerHeight ( ) ) ,
79+ 25
80+ ) ,
81+ } )
82+ . fadeIn ( 200 ) ;
6383 clearTimeout ( scrollTimer ) ;
6484 scrollTimer = setTimeout ( function ( ) {
6585 $ ( ".ni-footer-navtop" ) . fadeOut ( 500 ) ;
6686 } , 2000 ) ;
67- }
87+ } ;
6888 $ ( ".ni-footer-navtop" ) . on ( {
6989 "mouseenter" : function ( ) {
7090 clearTimeout ( scrollTimer ) ;
@@ -73,8 +93,44 @@ $(function () {
7393 scrollTimer = setTimeout ( function ( ) {
7494 $ ( ".ni-footer-navtop" ) . fadeOut ( 500 ) ;
7595 } , 2000 ) ;
76- }
77- } )
96+ } ,
97+ } ) ;
7898 windowScroll ( ) ;
7999 $ ( window ) . on ( "scroll" , windowScroll ) ;
80- } ) ;
100+
101+ /* 图片 视频链接点击*/
102+ $ ( ".figure-link, .video-link" ) . on ( "click" , function ( e ) {
103+ let link = $ ( this ) . attr ( "href" ) ;
104+ console . log ( link ) ;
105+ if ( link . match ( / \. m p 4 $ / ) ) {
106+ $ ( `<video/>` )
107+ . addClass ( "ni-modal-video" )
108+ . attr ( {
109+ "src" : link ,
110+ "controls" : "controls" ,
111+ "autoplay" : "autoplay" ,
112+ } )
113+ . appendTo ( $ ( ".ni-modal-content" ) . empty ( ) ) ;
114+ } else if ( link . match ( / \. (?: b m p | j p e ? g | g i f | p n g ) $ / ) ) {
115+ $ ( `<img/>` ) . addClass ( "ni-modal-image" ) . attr ( "src" , link ) . appendTo ( $ ( ".ni-modal-content" ) . empty ( ) ) ;
116+ } else if ( link . match ( / y o u t u b e \. c o m \/ w a t c h / ) ) {
117+ let video_id = link . match ( / (?< = \/ w a t c h \? v = ) [ ^ \? & ] + / ) [ 0 ] ;
118+ let video_args = ( link . match ( / (?< = [ \? & ] ) .+ $ / ) || "" ) [ 0 ] ;
119+ console . log ( video_id , video_args ) ;
120+ $ ( `<iframe/>` )
121+ . addClass ( "ni-modal-youtube" )
122+ . attr ( {
123+ "src" : `https://youtube.com/embed/${ video_id } ?autoplay=1&controls=1&${ video_args } ` ,
124+ "allowfullscreen" : "allowfullscreen" ,
125+ "allow" :
126+ "accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" ,
127+ } )
128+ . appendTo ( $ ( ".ni-modal-content" ) . empty ( ) ) ;
129+ }
130+ $ ( ".ni-modal" ) . modal ( "show" ) ;
131+ e . preventDefault ( ) ;
132+ } ) ;
133+ $ ( ".ni-modal" ) . on ( "hide.bs.modal" , function ( ) {
134+ $ ( ".ni-modal-content" ) . empty ( ) ;
135+ } ) ;
136+ } ) ;
0 commit comments