@@ -3031,15 +3031,127 @@ function getAndActive (router, el, isParent, autoTitle) {
3031
3031
return target
3032
3032
}
3033
3033
3034
+ var _createClass = function ( ) { function defineProperties ( target , props ) { for ( var i = 0 ; i < props . length ; i ++ ) { var descriptor = props [ i ] ; descriptor . enumerable = descriptor . enumerable || false ; descriptor . configurable = true ; if ( "value" in descriptor ) { descriptor . writable = true ; } Object . defineProperty ( target , descriptor . key , descriptor ) ; } } return function ( Constructor , protoProps , staticProps ) { if ( protoProps ) { defineProperties ( Constructor . prototype , protoProps ) ; } if ( staticProps ) { defineProperties ( Constructor , staticProps ) ; } return Constructor ; } ; } ( ) ;
3035
+
3036
+ function _classCallCheck ( instance , Constructor ) { if ( ! ( instance instanceof Constructor ) ) { throw new TypeError ( "Cannot call a class as a function" ) ; } }
3037
+
3038
+ var Tweezer = function ( ) {
3039
+ function Tweezer ( ) {
3040
+ var opts = arguments . length > 0 && arguments [ 0 ] !== undefined ? arguments [ 0 ] : { } ;
3041
+
3042
+ _classCallCheck ( this , Tweezer ) ;
3043
+
3044
+ this . duration = opts . duration || 1000 ;
3045
+ this . ease = opts . easing || this . _defaultEase ;
3046
+ this . start = opts . start ;
3047
+ this . end = opts . end ;
3048
+
3049
+ this . frame = null ;
3050
+ this . next = null ;
3051
+ this . isRunning = false ;
3052
+ this . events = { } ;
3053
+ this . direction = this . start < this . end ? 'up' : 'down' ;
3054
+ }
3055
+
3056
+ _createClass ( Tweezer , [ {
3057
+ key : 'begin' ,
3058
+ value : function begin ( ) {
3059
+ if ( ! this . isRunning && this . next !== this . end ) {
3060
+ this . frame = window . requestAnimationFrame ( this . _tick . bind ( this ) ) ;
3061
+ }
3062
+ return this ;
3063
+ }
3064
+ } , {
3065
+ key : 'stop' ,
3066
+ value : function stop ( ) {
3067
+ window . cancelAnimationFrame ( this . frame ) ;
3068
+ this . isRunning = false ;
3069
+ this . frame = null ;
3070
+ this . timeStart = null ;
3071
+ this . next = null ;
3072
+ return this ;
3073
+ }
3074
+ } , {
3075
+ key : 'on' ,
3076
+ value : function on ( name , handler ) {
3077
+ this . events [ name ] = this . events [ name ] || [ ] ;
3078
+ this . events [ name ] . push ( handler ) ;
3079
+ return this ;
3080
+ }
3081
+ } , {
3082
+ key : 'emit' ,
3083
+ value : function emit ( name , val ) {
3084
+ var _this = this ;
3085
+
3086
+ var e = this . events [ name ] ;
3087
+ e && e . forEach ( function ( handler ) {
3088
+ return handler . call ( _this , val ) ;
3089
+ } ) ;
3090
+ }
3091
+ } , {
3092
+ key : '_tick' ,
3093
+ value : function _tick ( currentTime ) {
3094
+ this . isRunning = true ;
3095
+
3096
+ var lastTick = this . next || this . start ;
3097
+
3098
+ if ( ! this . timeStart ) { this . timeStart = currentTime ; }
3099
+ this . timeElapsed = currentTime - this . timeStart ;
3100
+ this . next = Math . round ( this . ease ( this . timeElapsed , this . start , this . end - this . start , this . duration ) ) ;
3101
+
3102
+ if ( this . _shouldTick ( lastTick ) ) {
3103
+ this . emit ( 'tick' , this . next ) ;
3104
+ this . frame = window . requestAnimationFrame ( this . _tick . bind ( this ) ) ;
3105
+ } else {
3106
+ this . emit ( 'tick' , this . end ) ;
3107
+ this . emit ( 'done' , null ) ;
3108
+ }
3109
+ }
3110
+ } , {
3111
+ key : '_shouldTick' ,
3112
+ value : function _shouldTick ( lastTick ) {
3113
+ return {
3114
+ up : this . next < this . end && lastTick <= this . next ,
3115
+ down : this . next > this . end && lastTick >= this . next
3116
+ } [ this . direction ] ;
3117
+ }
3118
+ } , {
3119
+ key : '_defaultEase' ,
3120
+ value : function _defaultEase ( t , b , c , d ) {
3121
+ if ( ( t /= d / 2 ) < 1 ) { return c / 2 * t * t + b ; }
3122
+ return - c / 2 * ( -- t * ( t - 2 ) - 1 ) + b ;
3123
+ }
3124
+ } ] ) ;
3125
+
3126
+ return Tweezer ;
3127
+ } ( ) ;
3128
+
3034
3129
var nav = { } ;
3035
3130
var hoverOver = false ;
3131
+ var scroller = null ;
3132
+ var enableScrollEvent = true ;
3133
+
3134
+ function scrollTo ( el ) {
3135
+ if ( scroller ) { scroller . stop ( ) ; }
3136
+ enableScrollEvent = false ;
3137
+ scroller = new Tweezer ( {
3138
+ start : window . scrollY ,
3139
+ end : el . getBoundingClientRect ( ) . top + window . scrollY ,
3140
+ duration : 500
3141
+ } )
3142
+ . on ( 'tick' , function ( v ) { return window . scrollTo ( 0 , v ) ; } )
3143
+ . on ( 'done' , function ( ) { enableScrollEvent = true ; scroller = null ; } )
3144
+ . begin ( ) ;
3145
+ }
3036
3146
3037
3147
function highlight ( ) {
3148
+ if ( ! enableScrollEvent ) { return }
3038
3149
var sidebar = getNode ( '.sidebar' ) ;
3039
3150
var anchors = findAll ( '.anchor' ) ;
3040
3151
var wrap = find ( sidebar , '.sidebar-nav' ) ;
3041
3152
var active = find ( sidebar , 'li.active' ) ;
3042
- var top = body . scrollTop ;
3153
+ var doc = document . documentElement ;
3154
+ var top = doc && doc . scrollTop || document . body . scrollTop ;
3043
3155
var last ;
3044
3156
3045
3157
for ( var i = 0 , len = anchors . length ; i < len ; i += 1 ) {
@@ -3109,7 +3221,13 @@ function scrollActiveSidebar (router) {
3109
3221
3110
3222
function scrollIntoView ( id ) {
3111
3223
var section = find ( '#' + id ) ;
3112
- section && section . scrollIntoView ( ) ;
3224
+ section && scrollTo ( section ) ;
3225
+
3226
+ var li = nav [ id ] ;
3227
+ var sidebar = getNode ( '.sidebar' ) ;
3228
+ var active = find ( sidebar , 'li.active' ) ;
3229
+ active && active . classList . remove ( 'active' ) ;
3230
+ li && li . classList . add ( 'active' ) ;
3113
3231
}
3114
3232
3115
3233
var scrollEl = $ . scrollingElement || $ . documentElement ;
@@ -3826,7 +3944,7 @@ initGlobalAPI();
3826
3944
/**
3827
3945
* Version
3828
3946
*/
3829
- Docsify . version = '4.3.0 ' ;
3947
+ Docsify . version = '4.3.1 ' ;
3830
3948
3831
3949
/**
3832
3950
* Run Docsify
0 commit comments