@@ -11,6 +11,7 @@ $.fn.extend({
11
11
12
12
this . each ( function ( ) {
13
13
var opts = $ . extend ( { } , $ . fn . smoothScroll . defaults , options ) ;
14
+
14
15
$ ( this ) . bind ( 'click' , function ( event ) {
15
16
var link = this , $link = $ ( this ) ,
16
17
hostMatch = ( ( location . hostname === link . hostname ) || ! link . hostname ) ,
@@ -39,6 +40,7 @@ $.fn.extend({
39
40
40
41
if ( include ) {
41
42
opts . scrollTarget = opts . scrollTarget || thisHash ;
43
+ opts . link = link ;
42
44
event . preventDefault ( ) ;
43
45
$ . smoothScroll ( opts ) ;
44
46
}
@@ -61,22 +63,27 @@ $.smoothScroll = function(options, px) {
61
63
scrollTargetOffset = options ;
62
64
} else {
63
65
opts = $ . extend ( { } , $ . fn . smoothScroll . defaults , options ) ;
64
- scrollTargetOffset = $ ( opts . scrollTarget ) . offset ( ) . top ;
66
+ scrollTargetOffset = px || $ ( opts . scrollTarget ) . offset ( ) . top ;
65
67
}
66
-
68
+ opts = $ . extend ( { link : null } , opts ) ;
69
+
67
70
$ ( scrollElem ) . animate ( {
68
71
scrollTop : scrollTargetOffset + opts . offset
69
72
} ,
70
73
{
71
74
duration : opts . speed ,
72
- easing : opts . easing
73
- } , function ( ) {
74
- opts . afterScroll . call ( link ) ;
75
+ easing : opts . easing ,
76
+ complete : function ( ) {
77
+ if ( opts . afterScroll && $ . isFunction ( opts . afterScroll ) ) {
78
+ opts . afterScroll . call ( opts . link , opts ) ;
79
+ }
80
+ }
75
81
} ) ;
76
82
77
83
} ;
78
84
79
85
$ . smoothScroll . version = version ;
86
+
80
87
// default options
81
88
$ . fn . smoothScroll . defaults = {
82
89
exclude : [ ] ,
0 commit comments