Skip to content
This repository has been archived by the owner on Sep 16, 2020. It is now read-only.

Commit

Permalink
usage of jump.js for the smooth scrolling
Browse files Browse the repository at this point in the history
  • Loading branch information
Loïc Goyet committed Apr 26, 2017
1 parent f6c3548 commit e713822
Show file tree
Hide file tree
Showing 7 changed files with 204 additions and 9 deletions.
189 changes: 186 additions & 3 deletions dest/javascript/covers.js

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

2 changes: 1 addition & 1 deletion dest/javascript/covers.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dest/javascript/covers.min.js

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
],
"homepage": "https://github.com/FriendsOfTrowel/Covers#readme",
"dependencies": {
"jump.js": "^1.0.2",
"trowel-core": "^4.0.2"
},
"devDependencies": {
Expand Down
11 changes: 8 additions & 3 deletions src/javascript/covers.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import jump from '../../node_modules/jump.js';


export default class TrowelCovers {
constructor(elements, options = {}) {
[].slice.call(elements).forEach(function(element, index) {
Expand All @@ -18,7 +21,7 @@ class TrowelCover {
_setOptions(customOptions) {
const defaultOptions = {
scrollDuration: 500,
topOffset: 0,
offset: 0,
};

let options = {};
Expand All @@ -38,8 +41,10 @@ class TrowelCover {
}

scrollDown() {
const scrollTop = this.element.offsetTop + this.element.offsetHeight - this.options.topOffset;
return this._smoothScrollTo(document.body, scrollTop, this.options.scrollDuration);
const scrollTop = this.element.offsetTop + this.element.offsetHeight + this.options.offset;
return jump(scrollTop, {
duration: this.options.scrollDuration,
});
}

_smoothScrollTo(element, target, duration) {
Expand Down
4 changes: 3 additions & 1 deletion test/src/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@

<script src="./javascript/covers.js"></script>
<script type="text/javascript">
var covers = new TrowelCovers(document.querySelectorAll('.cover'));
var covers = new TrowelCovers(document.querySelectorAll('.cover'), {
offset: -100,
});
</script>
</body>
</html>
4 changes: 4 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2494,6 +2494,10 @@ jsprim@^1.2.2:
json-schema "0.2.3"
verror "1.3.6"

jump.js:
version "1.0.2"
resolved "https://registry.yarnpkg.com/jump.js/-/jump.js-1.0.2.tgz#e0641b47f40a38f2139c25fda0500bf28e43015a"

kind-of@^3.0.2:
version "3.2.0"
resolved "https://registry.yarnpkg.com/kind-of/-/kind-of-3.2.0.tgz#b58abe4d5c044ad33726a8c1525b48cf891bff07"
Expand Down

0 comments on commit e713822

Please sign in to comment.