An open API service indexing awesome lists of open source software.

https://github.com/confusedmatrix/visibility-stats

A simple library to determine if DOM elements are visible in the viewport and statistics about how long elements have been visible / when they were last visible
https://github.com/confusedmatrix/visibility-stats

dom usability visibility

Last synced: 7 months ago
JSON representation

A simple library to determine if DOM elements are visible in the viewport and statistics about how long elements have been visible / when they were last visible

Awesome Lists containing this project

README

          

# VisibilityStats
A simple library to determine if DOM elements are visible in the
viewport and statistics about how long elements have been visible
/ when they were last visible.

This library could be useful for determining which content is most
looked at on a page and therefore could be a measure of how good/useful
a particular content section is.

## Intallation
In the browser:
```

```

Via npm
```shell
npm i --save visibility-stats
```

## Usage

Sample HTML
```html
<div id="watch-me"></div>
<div id="watch-me-too"></div>
```

```html
<script>
// Initialise the library with a DOM query selector to
// begin tracking the visibily of certain elements
var vs = new VisibilityStats("#watch-me, #watch-me-too")

// return all currently visible elements
vs.getVisibleElements()

// get up to date stats on which elements are visible and how
// long they have been visible for / when they were last visible
vs.getStats()

```

For more examples, see the `/examples` directory

## Build devlopment bundle
`yarn build:dev`

or to additional watch for changes and rebuild bundle
`yarn build:dev:watch`

## Compile production library to dist
`yarn build:prod`

## Run tests (TBD)
`yarn test`