You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: readme.md
+18-7Lines changed: 18 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -47,9 +47,12 @@ The following options, shown with their default values, are available for both `
47
47
// one of 'top' or 'left'
48
48
direction:'top',
49
49
50
-
// only use if you want to override default behavior
50
+
// only use if you want to override default behavior or if using $.smoothScroll
51
51
scrollTarget:null,
52
52
53
+
// automatically focus the target element after scrolling to it (see readme for details)
54
+
autoFocus:false,
55
+
53
56
// string to use as selector for event delegation
54
57
delegateSelector:null,
55
58
@@ -67,7 +70,7 @@ The following options, shown with their default values, are available for both `
67
70
68
71
// speed can be a number or 'auto'
69
72
// if 'auto', the speed will be calculated based on the formula:
70
-
// (current scroll position - target scroll position) / autoCoeffic
73
+
// (current scroll position - target scroll position) / autoCoefficient
71
74
speed:400,
72
75
73
76
// autoCoefficent: Only used when speed set to "auto".
@@ -185,7 +188,12 @@ if (reSmooth.test(location.hash)) {
185
188
186
189
## Focus element after scrolling to it.
187
190
188
-
Imagine you have a link to a form somewhere on the same page. When the user clicks the link, you want the user to be able to begin interacting with that form. With the smoothScroll plugin, you can use the `afterScroll` callback function. Here is an example that focuses the first input within the form after scrolling to the form:
191
+
Imagine you have a link to a form somewhere on the same page. When the user clicks the link, you want the user to be able to begin interacting with that form.
192
+
193
+
* As of **smoothScroll version 2.2**, the plugin will automatically focus the element if you set the `autoFocus` option to `true`.
194
+
* In the future, versions 3.x and later will have `autoFocus` set to true **by default**.
195
+
* If you are using the low-level `$.smoothScroll` method, `autoFocus` will only work if you've also provided a value for the `scrollTarget` option.
196
+
* Prior to version 2.2, you can use the `afterScroll` callback function. Here is an example that focuses the first input within the form after scrolling to the form:
For accessibility reasons, it might make sense to focus any element you scroll to, even if it's not a natively focusable element. To do so, you could add a `tabIndex` attribute to the target element:
207
+
For accessibility reasons, it might make sense to focus any element you scroll to, even if it's not a natively focusable element. To do so, you could add a `tabIndex` attribute to the target element (this, again, is for versions prior to 2.2):
200
208
201
209
```js
202
-
$('a.example').smoothScroll({
210
+
$('div.example').smoothScroll({
203
211
afterScroll:function(options) {
204
212
var $tgt =$(options.scrollTarget);
205
-
$tgt.attr('tabIndex', '0');
206
-
// Using $tgt[0] allows us to call .focus() on the DOM node itself, not the jQuery collection
0 commit comments