Skip to content

Commit

Permalink
adds util to chedk scroll direction
Browse files Browse the repository at this point in the history
  • Loading branch information
jadiehm committed Oct 24, 2023
1 parent e7c6362 commit fa7c985
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ Located in `src/utils/`.
// Usage
import example from "$utils/example.js";
```
* `checkScrollDir.js`: Gets the user's scroll direction ("up" or "down")
* `csvDownload.js`: Converts a flat array of data to CSV content ready to be used as an `href` value for download.
* `generateId.js`: Generate an alphanumeric id.
* `loadCsv.js`: Loads and parses a CSV file.
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

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

24 changes: 24 additions & 0 deletions src/utils/checkScrollDir.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* Usage
<script>
import checkScrollDir from "$utils/checkScrollDir.js";
let scrollY;
$: scrollDir = checkScrollDir(scrollY);
$: console.log(scrollDir)
</script>
<svelte:window bind:scrollY={scrollY} />
*/

let prevY = 0;
let scrollDir;

export default function checkScrollDir(scrollY) {
if (scrollY) {
scrollDir = scrollY > prevY ? "down" : "up";
prevY = scrollY;
return scrollDir;
} else {
scrollDir = undefined;
return scrollDir;
}
}

0 comments on commit fa7c985

Please sign in to comment.