Skip to content

Commit 9152ba0

Browse files
committed
Added the ability to pass an element as target
1 parent 1db30e4 commit 9152ba0

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,13 @@ Two parameters are required to make a jump:
4747

4848
#### Target
4949

50-
To jump to an element, pass a CSS selector as a string.
50+
To jump to an element, pass an element or a CSS selector string.
5151

5252
```es6
53+
Jump.jump(element, {
54+
// options...
55+
})
56+
5357
Jump.jump('.selector', {
5458
// options...
5559
})

dist/jump.min.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/jump.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,13 @@ export default class Jump {
1111
easing: options.easing || easeInOutQuad
1212
}
1313

14-
this.distance = typeof target === 'string'
15-
? this.options.offset + document.querySelector(target).getBoundingClientRect().top
16-
: target
14+
this.target = typeof target === 'string'
15+
? document.querySelector(target)
16+
: target;
17+
18+
this.distance = typeof target === 'number'
19+
? target
20+
: this.options.offset + target.getBoundingClientRect().top;
1721

1822
this.duration = typeof this.options.duration === 'function'
1923
? this.options.duration(this.distance)

0 commit comments

Comments
 (0)