Skip to content

Commit 1bf802e

Browse files
committed
Make sure beforeScroll fires before calculating scroll target
1 parent 080d3ae commit 1bf802e

File tree

4 files changed

+25
-20
lines changed

4 files changed

+25
-20
lines changed

demo/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
$(document).ready(function() {
3333

3434
$('ul.mainnav a').smoothScroll();
35+
3536
$('p.subnav a').click(function(event) {
3637
event.preventDefault();
3738
var link = this;

jquery.smooth-scroll.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
/*! Smooth Scroll - v1.4.6 - 2012-08-23
1+
/*! Smooth Scroll - v1.4.7 - 2012-10-29
22
* Copyright (c) 2012 Karl Swedberg; Licensed MIT, GPL */
33

44
(function($) {
55

6-
var version = '1.4.6',
6+
var version = '1.4.7',
77
defaults = {
88
exclude: [],
99
excludeWithin:[],
@@ -132,7 +132,8 @@ $.smoothScroll = function(options, px) {
132132
aniOpts = {},
133133
scrollprops = [];
134134

135-
if ( typeof options === 'number') {
135+
136+
if (typeof options === 'number') {
136137
opts = $.fn.smoothScroll.defaults;
137138
scrollTargetOffset = options;
138139
} else {
@@ -143,11 +144,6 @@ $.smoothScroll = function(options, px) {
143144
opts.scrollElement.css('position', 'relative');
144145
}
145146
}
146-
147-
scrollTargetOffset = px ||
148-
( $(opts.scrollTarget)[offPos]() &&
149-
$(opts.scrollTarget)[offPos]()[opts.direction] ) ||
150-
0;
151147
}
152148

153149
opts = $.extend({link: null}, opts);
@@ -160,10 +156,16 @@ $.smoothScroll = function(options, px) {
160156
$scroller = $('html, body').firstScrollable();
161157
}
162158

163-
aniProps[scrollDir] = scrollTargetOffset + scrollerOffset + opts.offset;
164-
159+
// beforeScroll callback function must fire before calculating offset
165160
opts.beforeScroll.call($scroller, opts);
166161

162+
scrollTargetOffset = (typeof options === 'number') ? options :
163+
px ||
164+
( $(opts.scrollTarget)[offPos]() &&
165+
$(opts.scrollTarget)[offPos]()[opts.direction] ) ||
166+
0;
167+
168+
aniProps[scrollDir] = scrollTargetOffset + scrollerOffset + opts.offset;
167169
speed = opts.speed;
168170

169171
// automatically calculate the speed of the scroll based on distance / coefficient

jquery.smooth-scroll.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/jquery.smooth-scroll.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ $.smoothScroll = function(options, px) {
129129
aniOpts = {},
130130
scrollprops = [];
131131

132-
if ( typeof options === 'number') {
132+
133+
if (typeof options === 'number') {
133134
opts = $.fn.smoothScroll.defaults;
134135
scrollTargetOffset = options;
135136
} else {
@@ -140,11 +141,6 @@ $.smoothScroll = function(options, px) {
140141
opts.scrollElement.css('position', 'relative');
141142
}
142143
}
143-
144-
scrollTargetOffset = px ||
145-
( $(opts.scrollTarget)[offPos]() &&
146-
$(opts.scrollTarget)[offPos]()[opts.direction] ) ||
147-
0;
148144
}
149145

150146
opts = $.extend({link: null}, opts);
@@ -157,10 +153,16 @@ $.smoothScroll = function(options, px) {
157153
$scroller = $('html, body').firstScrollable();
158154
}
159155

160-
aniProps[scrollDir] = scrollTargetOffset + scrollerOffset + opts.offset;
161-
156+
// beforeScroll callback function must fire before calculating offset
162157
opts.beforeScroll.call($scroller, opts);
163158

159+
scrollTargetOffset = (typeof options === 'number') ? options :
160+
px ||
161+
( $(opts.scrollTarget)[offPos]() &&
162+
$(opts.scrollTarget)[offPos]()[opts.direction] ) ||
163+
0;
164+
165+
aniProps[scrollDir] = scrollTargetOffset + scrollerOffset + opts.offset;
164166
speed = opts.speed;
165167

166168
// automatically calculate the speed of the scroll based on distance / coefficient

0 commit comments

Comments
 (0)