1
1
/*!
2
- * Jump.js 1. 0.0 - A small, modern, dependency-free smooth scrolling library.
2
+ * Jump.js 0.0.1 - A small, modern, dependency-free smooth scrolling library.
3
3
* Copyright (c) 2015 Michael Cavalea - https://github.com/callmecavs/jump.js
4
4
* License: MIT
5
5
*/
6
6
7
- ( function ( global , factory ) {
8
- if ( typeof define === 'function' && define . amd ) {
9
- define ( 'Jump' , [ 'exports' , 'module' ] , factory ) ;
10
- } else if ( typeof exports !== 'undefined' && typeof module !== 'undefined' ) {
11
- factory ( exports , module ) ;
12
- } else {
13
- var mod = {
14
- exports : { }
15
- } ;
16
- factory ( mod . exports , mod ) ;
17
- global . Jump = mod . exports ;
18
- }
19
- } ) ( this , function ( exports , module ) {
20
- 'use strict' ;
7
+ 'use strict' ;
21
8
22
- 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 ; } ; } ) ( ) ;
9
+ 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 ; } ; } ) ( ) ;
23
10
24
- function _classCallCheck ( instance , Constructor ) { if ( ! ( instance instanceof Constructor ) ) { throw new TypeError ( 'Cannot call a class as a function' ) ; } }
11
+ Object . defineProperty ( exports , "__esModule" , {
12
+ value : true
13
+ } ) ;
25
14
26
- var Jump = ( function ( ) {
27
- function Jump ( ) {
28
- var defaults = arguments . length <= 0 || arguments [ 0 ] === undefined ? { } : arguments [ 0 ] ;
15
+ function _classCallCheck ( instance , Constructor ) { if ( ! ( instance instanceof Constructor ) ) { throw new TypeError ( "Cannot call a class as a function" ) ; } }
29
16
30
- _classCallCheck ( this , Jump ) ;
17
+ var Jump = ( function ( ) {
18
+ function Jump ( ) {
19
+ _classCallCheck ( this , Jump ) ;
20
+ }
31
21
32
- this . duration = defaults . duration || 1000 ;
33
- this . offset = defaults . offset || 0 ;
34
- this . callback = defaults . callback || undefined ;
22
+ _createClass ( Jump , [ {
23
+ key : 'jump' ,
24
+ value : function jump ( target ) {
25
+ var _this = this ;
35
26
36
- this . easing = defaults . easing || function ( t , b , c , d ) {
37
- // Robert Penner's easeInOutQuad - http://robertpenner.com/easing/
38
- t /= d / 2 ;
39
- if ( t < 1 ) return c / 2 * t * t + b ;
40
- t -- ;
41
- return - c / 2 * ( t * ( t - 2 ) - 1 ) + b ;
42
- } ;
43
- }
27
+ var options = arguments . length <= 1 || arguments [ 1 ] === undefined ? { } : arguments [ 1 ] ;
44
28
45
- _createClass ( Jump , [ {
46
- key : 'jump' ,
47
- value : function jump ( target ) {
48
- var _this = this ;
29
+ this . start = window . pageYOffset ;
49
30
50
- var overrides = arguments . length <= 1 || arguments [ 1 ] === undefined ? { } : arguments [ 1 ] ;
51
-
52
- this . jumpStart = window . pageYOffset ;
31
+ this . options = {
32
+ duration : options . duration ,
33
+ offset : options . offset || 0 ,
34
+ callback : options . callback || undefined
35
+ } ;
53
36
54
- this . jumpDuration = overrides . duration || this . duration ;
55
- this . jumpOffset = overrides . offset || this . offset ;
56
- this . jumpCallback = overrides . callback || this . callback ;
57
- this . jumpEasing = overrides . easing || this . easing ;
37
+ this . distance = typeof target === 'string' ? this . options . offset + document . querySelector ( target ) . getBoundingClientRect ( ) . top : target ;
58
38
59
- this . jumpDistance = target . nodeType === 1 ? this . jumpOffset + Math . round ( target . getBoundingClientRect ( ) . top ) : target ;
39
+ requestAnimationFrame ( function ( time ) {
40
+ return _this . _loop ( time ) ;
41
+ } ) ;
42
+ }
43
+ } , {
44
+ key : '_loop' ,
45
+ value : function _loop ( time ) {
46
+ var _this2 = this ;
60
47
61
- requestAnimationFrame ( function ( time ) {
62
- return _this . _loop ( time ) ;
63
- } ) ;
48
+ if ( ! this . timeStart ) {
49
+ this . timeStart = time ;
64
50
}
65
- } , {
66
- key : '_loop' ,
67
- value : function _loop ( currentTime ) {
68
- var _this2 = this ;
69
51
70
- if ( ! this . timeStart ) {
71
- this . timeStart = currentTime ;
72
- }
52
+ this . timeElapsed = time - this . timeStart ;
53
+ this . next = this . _easing ( this . timeElapsed , this . start , this . distance , this . options . duration ) ;
73
54
74
- this . timeElapsed = currentTime - this . timeStart ;
75
- this . jumpNext = this . jumpEasing ( this . timeElapsed , this . jumpStart , this . jumpDistance , this . jumpDuration ) ;
55
+ window . scrollTo ( 0 , this . next ) ;
76
56
77
- window . scrollTo ( 0 , this . jumpNext ) ;
78
-
79
- this . timeElapsed < this . jumpDuration ? requestAnimationFrame ( function ( time ) {
80
- return _this2 . _loop ( time ) ;
81
- } ) : this . _end ( ) ;
82
- }
83
- } , {
84
- key : '_end' ,
85
- value : function _end ( ) {
86
- window . scrollTo ( 0 , this . jumpStart + this . jumpDistance ) ;
57
+ this . timeElapsed < this . options . duration ? requestAnimationFrame ( function ( time ) {
58
+ return _this2 . _loop ( time ) ;
59
+ } ) : this . _end ( ) ;
60
+ }
61
+ } , {
62
+ key : '_end' ,
63
+ value : function _end ( ) {
64
+ window . scrollTo ( 0 , this . start + this . distance ) ;
87
65
88
- typeof this . jumpCallback === 'function' && this . jumpCallback . call ( ) ;
89
- this . timeStart = false ;
90
- }
91
- } ] ) ;
66
+ typeof this . options . callback === 'function' && this . options . callback . call ( ) ;
67
+ this . timeStart = false ;
68
+ }
69
+ } , {
70
+ key : '_easing' ,
71
+ value : function _easing ( t , b , c , d ) {
72
+ // Robert Penner's easeInOutQuad - http://robertpenner.com/easing/
73
+ t /= d / 2 ;
74
+ if ( t < 1 ) return c / 2 * t * t + b ;
75
+ t -- ;
76
+ return - c / 2 * ( t * ( t - 2 ) - 1 ) + b ;
77
+ }
78
+ } ] ) ;
92
79
93
- return Jump ;
94
- } ) ( ) ;
80
+ return Jump ;
81
+ } ) ( ) ;
95
82
96
- module . exports = Jump ;
97
- } ) ;
83
+ exports . default = Jump ;
0 commit comments