Skip to content

Commit

Permalink
Merge pull request #56 from swup/next
Browse files Browse the repository at this point in the history
Update for swup 4
  • Loading branch information
hirasso authored Jul 26, 2023
2 parents da12a1f + 103150d commit af4e994
Show file tree
Hide file tree
Showing 5 changed files with 237 additions and 200 deletions.
65 changes: 65 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Changelog

<!-- ## [Unreleased] -->

## [3.0.0] - 2023-07-26

- Update for swup 4 compatibility

## [2.0.3] - 2023-06-12

- Make the plugin options optional

## [2.0.2] - 2023-03-02

- Correctly resolve URLs

## [2.0.1] - 2023-03-29

- Use shared browserslist config

## [2.0.0] - 2023-01-18

- Switch to microbundle
- Export native ESM module
- Upgrade scroll library

## [1.3.1] - 2022-08-30

- Wait for the next animationFrame before scrolling between pages

## [1.3.0] - 2022-08-19

- Store and restore scroll positions on the window and on overflowing divs
- Restore browser scrollRestoration on unmount

## [1.2.0] - 2022-08-07

- Allow fine-grained control over when to animate scroll
- Allow customizing how anchor element is found

## [1.1.1] - 2022-06-30

- Improve handling of scroll anchors with special characters

## [1.1.0] - 2021-03-13

- Allow setting custom scroll offset

## [1.0.0] - 2019-05-01

- Initial release

[Unreleased]: https://github.com/swup/scroll-plugin/compare/3.0.0...HEAD

[3.0.0]: https://github.com/swup/scroll-plugin/releases/tag/3.0.0
[2.0.3]: https://github.com/swup/scroll-plugin/releases/tag/2.0.3
[2.0.2]: https://github.com/swup/scroll-plugin/releases/tag/2.0.2
[2.0.1]: https://github.com/swup/scroll-plugin/releases/tag/2.0.1
[2.0.0]: https://github.com/swup/scroll-plugin/releases/tag/2.0.0
[1.3.1]: https://github.com/swup/scroll-plugin/releases/tag/1.3.1
[1.3.0]: https://github.com/swup/scroll-plugin/releases/tag/1.3.0
[1.2.0]: https://github.com/swup/scroll-plugin/releases/tag/1.2.0
[1.1.1]: https://github.com/swup/scroll-plugin/releases/tag/1.1.1
[1.1.0]: https://github.com/swup/scroll-plugin/releases/tag/1.1.0
[1.0.0]: https://github.com/swup/scroll-plugin/releases/tag/1.0.0
29 changes: 16 additions & 13 deletions readme.md → README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Swup Scroll plugin

Adds awesome "acceleration based" automatic scrolling into the process of page transitions. The scrolling behaviour is customizable using options (see below).
A [swup](https://swup.js.org) plugin for customizable smooth scrolling.

- Enables acceleration-based smooth scrolling
- Animates scroll position between page visits
- Animates scrolling to anchors
- Define a custom offset for scroll positions

## Installation

Expand All @@ -17,7 +22,7 @@ import SwupScrollPlugin from '@swup/scroll-plugin';
Or include the minified production file from a CDN:

```html
<script src="https://unpkg.com/@swup/scroll-plugin@2"></script>
<script src="https://unpkg.com/@swup/scroll-plugin@3"></script>
```

## Usage
Expand Down Expand Up @@ -103,7 +108,7 @@ Customize how the scroll target is found on the page. Defaults to standard brows
```javascript
{
// Use a custom data attribute instead of id
getAnchorElement: hash => {
getAnchorElement: (hash) => {
hash = hash.replace('#', '')
return document.querySelector(`[data-scroll-target="${hash}"]`)
}
Expand Down Expand Up @@ -168,27 +173,25 @@ new SwupScrollPlugin({
getAnchorElement: null,
offset: 0,
scrollContainers: `[data-swup-scroll-container]`,
shouldResetScrollPosition: htmlAnchorElement => true
shouldResetScrollPosition: (link) => true
});
```

## Changes of the swup instance
## Methods on the swup instance

Scroll Plugin adds the method `scrollTo` to the swup instance, which can be used for custom scrolling.
The method accepts an offset in pixels and a boolean, if the scroll position should be animated:
The method accepts a scroll position in pixels and a boolean whether the scroll position should be animated:

```js
// will animate the scroll position of the window to 2000px
swup.scrollTo(2000, true);
```

The Plugin also adds two new events `scrollStart` and `scrollDone` to swup, that can be listened to with the `on` method:
## Hooks

The plugin adds two new hooks `scroll:start` and `scroll:end` :

```js
swup.on('scrollStart', () => {
console.log('Swup started scrolling');
});
swup.on('scrollDone', () => {
console.log('Swup finished scrolling');
});
swup.hooks.on('scroll:start', () => console.log('Swup started scrolling'));
swup.hooks.on('scroll:end', () => console.log('Swup finished scrolling'));
```
90 changes: 51 additions & 39 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 5 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "@swup/scroll-plugin",
"amdName": "SwupScrollPlugin",
"version": "2.0.3",
"description": "Swup scroll plugin.",
"version": "3.0.0",
"description": "A swup plugin for customizable smooth scrolling",
"type": "module",
"source": "src/index.js",
"main": "./dist/index.cjs",
Expand All @@ -17,7 +17,7 @@
"dev": "swup-plugin dev",
"lint": "swup-plugin lint",
"format": "swup-plugin format",
"prepublish": "npm run build"
"prepublishOnly": "npm run build"
},
"author": {
"name": "Georgy Marchuk",
Expand All @@ -42,14 +42,11 @@
"url": "https://github.com/swup/scroll-plugin.git"
},
"dependencies": {
"@swup/plugin": "^2.0.0",
"@swup/plugin": "^3.0.0",
"scrl": "^2.0.0"
},
"devDependencies": {
"swup": "^3.0.0"
},
"peerDependencies": {
"swup": "^3.0.0"
"swup": "^4.0.0"
},
"browserslist": [
"extends @swup/browserslist-config"
Expand Down
Loading

0 comments on commit af4e994

Please sign in to comment.