File tree 1 file changed +7
-3
lines changed
1 file changed +7
-3
lines changed Original file line number Diff line number Diff line change 4
4
5
5
Vue . directive ( 'scrollspy' , {
6
6
twoWay : true ,
7
- params : [ "steps" , "time" ] ,
7
+ params : [ "steps" , "time" , "offset" ] ,
8
8
// {
9
9
// steps: {type: Number, required: false, default: 0},
10
10
// time: {type: Number, required: false, default: 0}
11
11
// },
12
12
scrollSections : [ ] ,
13
13
scroll : function ( ) {
14
- var pos = this . el . scrollTop
14
+ var offset = parseInt ( this . params . offset ) || 0
15
+ var pos = this . el . scrollTop + offset
15
16
var i = 0
16
17
while ( pos >= this . scrollSections [ i ] ) { i ++ }
17
18
this . set ( i ? i - 1 : 0 )
21
22
var target = this . scrollSections [ id ]
22
23
var time = parseInt ( this . params . time ) || 0
23
24
var steps = parseInt ( this . params . steps ) || 0
25
+ var offset = parseInt ( this . params . offset ) || 0
24
26
var el = this . el
25
27
28
+ target -= offset
29
+ target < 0 ? 0 : target
26
30
if ( ! steps ) {
27
31
el . scrollTop = target
28
32
} else {
37
41
}
38
42
} ,
39
43
init : function ( ) {
40
- this . scrollSections = [ 0 ]
44
+ this . scrollSections = [ ]
41
45
var sections = this . el . children
42
46
for ( var i = 0 ; i < sections . length ; i ++ ) {
43
47
if ( sections [ i ] . offsetTop > 0 ) {
You can’t perform that action at this time.
0 commit comments