Skip to content

Commit 16c8d29

Browse files
committed
Add ability to pass "step" callback function
1 parent 51ba3b2 commit 16c8d29

File tree

3 files changed

+33
-20
lines changed

3 files changed

+33
-20
lines changed

jquery.smooth-scroll.js

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
/*! Smooth Scroll - v1.4.5 - 2012-07-21
1+
/*! Smooth Scroll - v1.4.5 - 2012-07-22
22
* Copyright (c) 2012 Karl Swedberg; Licensed MIT, GPL */
33

4-
54
(function($) {
65

76
var version = '1.4.5',
@@ -117,7 +116,8 @@ $.smoothScroll = function(options, px) {
117116
scrollerOffset = 0,
118117
offPos = 'offset',
119118
scrollDir = 'scrollTop',
120-
aniprops = {},
119+
aniProps = {},
120+
aniOpts = {},
121121
useScrollTo = false,
122122
scrollprops = [];
123123

@@ -138,6 +138,7 @@ $.smoothScroll = function(options, px) {
138138
$(opts.scrollTarget)[offPos]()[opts.direction] ) ||
139139
0;
140140
}
141+
141142
opts = $.extend({link: null}, opts);
142143
scrollDir = opts.direction == 'left' ? 'scrollLeft' : scrollDir;
143144

@@ -149,12 +150,12 @@ $.smoothScroll = function(options, px) {
149150
useScrollTo = isTouch && 'scrollTo' in window;
150151
}
151152

152-
aniprops[scrollDir] = scrollTargetOffset + scrollerOffset + opts.offset;
153+
aniProps[scrollDir] = scrollTargetOffset + scrollerOffset + opts.offset;
153154

154155
opts.beforeScroll.call($scroller, opts);
155156

156157
if ( useScrollTo ) {
157-
scrollprops = (opts.direction == 'left') ? [aniprops[scrollDir], 0] : [0, aniprops[scrollDir]];
158+
scrollprops = (opts.direction == 'left') ? [aniProps[scrollDir], 0] : [0, aniProps[scrollDir]];
158159
window.scrollTo.apply(window, scrollprops);
159160
opts.afterScroll.call(opts.link, opts);
160161

@@ -164,21 +165,26 @@ $.smoothScroll = function(options, px) {
164165
// automatically calculate the speed of the scroll based on distance / coefficient
165166
if (speed === 'auto') {
166167

167-
// if aniprops[scrollDir] == 0 then we'll use scrollTop() value instead
168-
speed = aniprops[scrollDir] || $scroller.scrollTop();
168+
// if aniProps[scrollDir] == 0 then we'll use scrollTop() value instead
169+
speed = aniProps[scrollDir] || $scroller.scrollTop();
169170

170171
// divide the speed by the coefficient
171172
speed = speed / opts.autoCoefficent;
172173
}
173174

174-
$scroller.stop().animate(aniprops,
175-
{
175+
aniOpts = {
176176
duration: speed,
177177
easing: opts.easing,
178178
complete: function() {
179179
opts.afterScroll.call(opts.link, opts);
180180
}
181-
});
181+
};
182+
183+
if (opts.step) {
184+
aniOpts.step = opts.step;
185+
}
186+
187+
$scroller.stop().animate(aniProps, aniOpts);
182188
}
183189
};
184190

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: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ $.smoothScroll = function(options, px) {
113113
scrollerOffset = 0,
114114
offPos = 'offset',
115115
scrollDir = 'scrollTop',
116-
aniprops = {},
116+
aniProps = {},
117+
aniOpts = {},
117118
useScrollTo = false,
118119
scrollprops = [];
119120

@@ -134,6 +135,7 @@ $.smoothScroll = function(options, px) {
134135
$(opts.scrollTarget)[offPos]()[opts.direction] ) ||
135136
0;
136137
}
138+
137139
opts = $.extend({link: null}, opts);
138140
scrollDir = opts.direction == 'left' ? 'scrollLeft' : scrollDir;
139141

@@ -145,12 +147,12 @@ $.smoothScroll = function(options, px) {
145147
useScrollTo = isTouch && 'scrollTo' in window;
146148
}
147149

148-
aniprops[scrollDir] = scrollTargetOffset + scrollerOffset + opts.offset;
150+
aniProps[scrollDir] = scrollTargetOffset + scrollerOffset + opts.offset;
149151

150152
opts.beforeScroll.call($scroller, opts);
151153

152154
if ( useScrollTo ) {
153-
scrollprops = (opts.direction == 'left') ? [aniprops[scrollDir], 0] : [0, aniprops[scrollDir]];
155+
scrollprops = (opts.direction == 'left') ? [aniProps[scrollDir], 0] : [0, aniProps[scrollDir]];
154156
window.scrollTo.apply(window, scrollprops);
155157
opts.afterScroll.call(opts.link, opts);
156158

@@ -160,21 +162,26 @@ $.smoothScroll = function(options, px) {
160162
// automatically calculate the speed of the scroll based on distance / coefficient
161163
if (speed === 'auto') {
162164

163-
// if aniprops[scrollDir] == 0 then we'll use scrollTop() value instead
164-
speed = aniprops[scrollDir] || $scroller.scrollTop();
165+
// if aniProps[scrollDir] == 0 then we'll use scrollTop() value instead
166+
speed = aniProps[scrollDir] || $scroller.scrollTop();
165167

166168
// divide the speed by the coefficient
167169
speed = speed / opts.autoCoefficent;
168170
}
169171

170-
$scroller.stop().animate(aniprops,
171-
{
172+
aniOpts = {
172173
duration: speed,
173174
easing: opts.easing,
174175
complete: function() {
175176
opts.afterScroll.call(opts.link, opts);
176177
}
177-
});
178+
};
179+
180+
if (opts.step) {
181+
aniOpts.step = opts.step;
182+
}
183+
184+
$scroller.stop().animate(aniProps, aniOpts);
178185
}
179186
};
180187

0 commit comments

Comments
 (0)