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
+24-4Lines changed: 24 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -83,8 +83,8 @@ smoothScroll.init({
83
83
speed:500, // Integer. How fast to complete the scroll in milliseconds
84
84
easing:'easeInOutCubic', // Easing pattern to use
85
85
offset:0, // Integer. How far to offset the scrolling anchor location in pixels
86
-
scrollOnLoad:true, // Boolean. If true, animate to anchor on page load if URL has a hash
87
-
callback:function ( toggle, anchor ) {} // Function to run after scrolling
86
+
updateURL:true, // Boolean. If true, update the URL hash on scroll
87
+
callback:function ( anchor, toggle ) {} // Function to run after scrolling
88
88
});
89
89
```
90
90
@@ -203,9 +203,29 @@ Add a `[data-scroll-header]` data attribute to fixed headers. Smooth Scroll will
203
203
</nav>
204
204
```
205
205
206
-
### Animating links to other pages[NEW in v10]
206
+
### Animating links to other pages
207
207
208
-
Smooth Scroll now supports animating anchor links to other pages. Simply make sure that `scrollOnLoad` is set to `true` (the default) and point your link to the anchor on the page as normal.
208
+
This is an often requested feature, but Smooth Scroll does not include an option to animate scrolling to links on other pages.
209
+
210
+
You can attempt to implement it using the API, but it's very difficult to prevent the automatic browser jump when the page loads, and anything I've done to work around it results in weird, janky issues, so I've decided to leave this out of the core. Here's a potential workaround...
211
+
212
+
1. Do *not* add the `data-scroll` attribute to links to other pages. Treat them like normal links, and include your anchor link hash as normal.
213
+
214
+
```html
215
+
<ahref="some-page.html#example">
216
+
```
217
+
2. Add the following script to the footer of your page, after the `smoothScroll.init()` function.
218
+
219
+
```html
220
+
<script>
221
+
if ( window.location.hash ) {
222
+
var hash =smoothScroll.escapeCharacters( window.location.hash ); // Escape the hash
223
+
var toggle =document.querySelector( 'a[href*="'+ hash +'"]' ); // Get the toggle (if one exists)
224
+
var options = {}; // Any custom options you want to use would go here
0 commit comments