Skip to content

Commit d4afd9f

Browse files
authored
v10.0.0 (cferdinandi#283)
BREAKING CHANGES: - Use `hashchange` instead of `pushState` for better browser support - Remove `updateUrl` option, since URL will always update - Fixed focus state approach - Pass Node or Number, not ID string, into `animateScroll` method - Remove `escapeCharacters` from public API - If scrolling to top with `#`, add an ID to the body and scroll that way - Only look for fixed header if a selector for one is set
1 parent 7f32bdb commit d4afd9f

File tree

8 files changed

+476
-240
lines changed

8 files changed

+476
-240
lines changed

README.md

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,10 @@ You can pass options and callbacks into Smooth Scroll through the `init()` funct
7979
```javascript
8080
smoothScroll.init({
8181
selector: '[data-scroll]', // Selector for links (must be a class, ID, data attribute, or element tag)
82-
selectorHeader: '[data-scroll-header]', // Selector for fixed headers (must be a valid CSS selector)
82+
selectorHeader: null, // Selector for fixed headers (must be a valid CSS selector) [optional]
8383
speed: 500, // Integer. How fast to complete the scroll in milliseconds
8484
easing: 'easeInOutCubic', // Easing pattern to use
8585
offset: 0, // Integer. How far to offset the scrolling anchor location in pixels
86-
updateURL: true, // Boolean. If true, update the URL hash on scroll
8786
callback: function ( anchor, toggle ) {} // Function to run after scrolling
8887
});
8988
```
@@ -154,39 +153,35 @@ Animate scrolling to an anchor.
154153

155154
```javascript
156155
smoothScroll.animateScroll(
157-
anchor, // ID of the anchor to scroll to. ex. '#bazinga'
158-
toggle, // Node that toggles the animation, OR an integer. ex. document.querySelector('#toggle')
156+
anchor, // Node to scroll to. ex. document.querySelector( '#bazinga' )
157+
toggle, // Node that toggles the animation, OR an integer. ex. document.querySelector( '#toggle' )
159158
options // Classes and callbacks. Same options as those passed into the init() function.
160159
);
161160
```
162161

163162
**Example 1**
164163

165164
```javascript
166-
smoothScroll.animateScroll( '#bazinga' );
165+
var anchor = document.querySelector( '#bazinga' );
166+
smoothScroll.animateScroll( anchor );
167167
```
168168

169169
**Example 2**
170170

171171
```javascript
172+
var anchor = document.querySelector( '#bazinga' );
172173
var toggle = document.querySelector('#toggle');
173174
var options = { speed: 1000, easing: 'easeOutCubic' };
174-
smoothScroll.animateScroll( '#bazinga', toggle, options );
175+
smoothScroll.animateScroll( anchor, toggle, options );
175176
```
176177

177178
**Example 3**
178179

179180
```javascript
181+
// You can optionally pass in a y-position to scroll to as an integer
180182
smoothScroll.animateScroll( 750 );
181183
```
182184

183-
#### escapeCharacters()
184-
Escape special characters for use with `animateScroll()`.
185-
186-
```javascript
187-
var toggle = smoothScroll.escapeCharacters('#1@#%^-');
188-
```
189-
190185
#### destroy()
191186
Destroy the current `smoothScroll.init()`. This is called automatically during the `init` function to remove any existing initializations.
192187

@@ -197,12 +192,20 @@ smoothScroll.destroy();
197192

198193
### Fixed Headers
199194

200-
Add a `[data-scroll-header]` data attribute to fixed headers. Smooth Scroll will automatically offset scroll distances by the header height. If you have multiple fixed headers, add `[data-scroll-header]` to the last one in the markup.
195+
If you're using a fixed header, Smooth Scroll will automatically offset scroll distances by the header height. Pass in a valid CSS selector for your fixed header as an option to the `init`.
196+
197+
If you have multiple fixed headers, pass in the last one in the markup.
201198

202199
```html
203200
<nav data-scroll-header>
204201
...
205202
</nav>
203+
...
204+
<script>
205+
smoothScroll.init({
206+
selectorHeader: '[data-scroll-header]'
207+
});
208+
</script>
206209
```
207210

208211
### Animating links to other pages
@@ -221,10 +224,10 @@ You can attempt to implement it using the API, but it's very difficult to preven
221224
```html
222225
<script>
223226
if ( window.location.hash ) {
224-
var hash = smoothScroll.escapeCharacters( window.location.hash ); // Escape the hash
225-
var toggle = document.querySelector( 'a[href*="' + hash + '"]' ); // Get the toggle (if one exists)
227+
var anchor = document.querySelector( window.location.hash ); // Get the anchor
228+
var toggle = document.querySelector( 'a[href*="' + window.location.hash + '"]' ); // Get the toggle (if one exists)
226229
var options = {}; // Any custom options you want to use would go here
227-
smoothScroll.animateScroll( hash, toggle, options );
230+
smoothScroll.animateScroll( anchor, toggle, options );
228231
}
229232
</script>
230233
```
@@ -234,8 +237,7 @@ You can attempt to implement it using the API, but it's very difficult to preven
234237

235238
Smooth Scroll works in all modern browsers, and IE 9 and above.
236239

237-
Smooth Scroll is built with modern JavaScript APIs, and uses progressive enhancement. If the JavaScript file fails to load, or if your site is viewed on older and less capable browsers, anchor links will jump the way they normally would. If you need to smooth scrolling for older browsers, [download the jQuery version of Smooth Scroll on GitHub](https://github.com/cferdinandi/smooth-scroll/tree/archive-v1).
238-
240+
Smooth Scroll is built with modern JavaScript APIs, and uses progressive enhancement. If the JavaScript file fails to load, or if your site is viewed on older and less capable browsers, anchor links will jump the way they normally would.
239241

240242

241243
## Known Issues

0 commit comments

Comments
 (0)