Skip to content

Commit

Permalink
perf: change data attr and default class name
Browse files Browse the repository at this point in the history
  • Loading branch information
aryehraber committed Feb 9, 2018
1 parent 415cddc commit 4553268
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,20 @@ scrollinview(event)
```

```html
<div class="content" data-inview>
<div class="content" data-scroll-in-view>
<!-- Content here -->
</div>
```

As soon as the element enters the viewport, a `js-in-view` class is added allowing a css animation to be triggered — this class can also be customised using an option (see below).
As soon as the element enters the viewport, a `js-scroll-in-view` class is added allowing a css animation to be triggered — this class can also be customised using an option (see below).

### Options

The `scrollinview` function can optionally take an object as the second argument, that may include the following properties.

### className

The class name that Scroll in View uses when an element enters the viewport (defaults to `js-in-view`).
The class name that Scroll in View uses when an element enters the viewport (defaults to `js-scroll-in-view`).

```js
scrollinview(event, { className: 'my-custom-class' })
Expand Down
16 changes: 8 additions & 8 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
let inViewClass
let scrollInViewClass

const check = (item, i, start, now, height) => {
const delay = parseInt(item.dataset.inviewDelay, 10) || 0
const offset = parseInt(item.dataset.inview, 10) || 0
const delay = parseInt(item.dataset.scrollInViewDelay, 10) || 0
const offset = parseInt(item.dataset.scrollInView, 10) || 0

if (now >= start + delay) {
const top = item.getBoundingClientRect().top

if (height > top + offset) {
item.classList.add(inViewClass)
item.classList.add(scrollInViewClass)
}
}

return item
}

const notDone = item => ! item.classList.contains(inViewClass)
const notDone = item => ! item.classList.contains(scrollInViewClass)

const init = (event, {
className = 'js-in-view'
className = 'js-scroll-in-view'
} = {}) => {
const start = Date.now()

inViewClass = className
scrollInViewClass = className

let items = [ ...document.querySelectorAll('[data-inview]') ]
let items = [ ...document.querySelectorAll('[data-scroll-in-view]') ]

const token = event.subscribe('newContent', () => {
const now = Date.now()
Expand Down

0 comments on commit 4553268

Please sign in to comment.