All Projects → xtianmiller → Emergence.js

xtianmiller / Emergence.js

Licence: mit
Detect element visibility in the browser

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Emergence.js

onscroll-effect
A tiny JavaScript library to enable CSS animations when user scrolls.
Stars: ✭ 35 (-98.15%)
Mutual labels:  scroll, viewport
React Intersection Observer
React implementation of the Intersection Observer API to tell you when an element enters or leaves the viewport.
Stars: ✭ 2,689 (+42.2%)
Mutual labels:  viewport, visibility
Scrollreveal
Animate elements as they scroll into view.
Stars: ✭ 20,264 (+971.6%)
Mutual labels:  scroll, reveal
react-scroll-trigger
📜 React component that monitors scroll events to trigger callbacks when it enters, exits and progresses through the viewport. All callback include the progress and velocity of the scrolling, in the event you want to manipulate stuff based on those values.
Stars: ✭ 126 (-93.34%)
Mutual labels:  scroll, viewport
react-awesome-reveal
React components to add reveal animations using the Intersection Observer API and CSS Animations.
Stars: ✭ 564 (-70.17%)
Mutual labels:  viewport, reveal
Scrollmonitor
A simple and fast API to monitor elements as you scroll
Stars: ✭ 3,250 (+71.87%)
Mutual labels:  viewport, scroll
Motus
Animation library that mimics CSS keyframes when scrolling.
Stars: ✭ 502 (-73.45%)
Mutual labels:  viewport, scroll
Use Is In Viewport
A react hook to find out if an element is in a given viewport with a simple api.
Stars: ✭ 129 (-93.18%)
Mutual labels:  viewport
Sparselizard
C++ FEM library | user-friendly | multi-physics | hp-adaptive
Stars: ✭ 145 (-92.33%)
Mutual labels:  element
Vue Todos
vue最新实战项目教程,从零开始,一步一个脚印,循序渐进。跟着我一起学习vue吧!
Stars: ✭ 1,659 (-12.27%)
Mutual labels:  element
Familybucket Ui
微服务UI端-配置管理-网关管理-追踪展示-日志查询-监控查看-服务管理......
Stars: ✭ 120 (-93.65%)
Mutual labels:  element
Nutzwk
WK系列开发框架-V1至V5 Java开源企业级开发框架(单应用/微服务/分布式)
Stars: ✭ 1,629 (-13.86%)
Mutual labels:  element
Ngx Ui Scroll
Infinite/virtual scroll for Angular
Stars: ✭ 145 (-92.33%)
Mutual labels:  scroll
D2 Admin
An elegant dashboard
Stars: ✭ 11,012 (+482.34%)
Mutual labels:  element
Ifvisible.js
Crossbrowser & lightweight way to check if user is looking at the page or interacting with it.
Stars: ✭ 1,896 (+0.26%)
Mutual labels:  visibility
Fantastic Admin
一款开箱即用的 Vue 中后台管理系统框架,基于ElementUI,兼容PC、移动端,vue-admin, vue-element-admin, vue后台
Stars: ✭ 153 (-91.91%)
Mutual labels:  element
React Scrollchor
A React component for scroll to `#hash` links with smooth animations
Stars: ✭ 141 (-92.54%)
Mutual labels:  scroll
Flowless
Efficient VirtualFlow for JavaFX
Stars: ✭ 120 (-93.65%)
Mutual labels:  viewport
React Locky
"🔒-y" – Asgardian God of Event Scoping 📦, Scroll Locking 📜, Silence Casting 🙊
Stars: ✭ 141 (-92.54%)
Mutual labels:  scroll
Scrollprogress
🛸 Light weight library to observe the viewport scroll position
Stars: ✭ 148 (-92.17%)
Mutual labels:  scroll

Emergence.js - detect element visibility in the browser

Emergence.js is a lightweight, high-performance JS plugin for detecting and manipulating elements in the browser.

Emergence.js - detect element visibility in the browser


License: MIT NPM version CDNJS version

  • Dependancy-free
  • IE8+ and all modern browsers
  • 1KB minified and gzipped

View Demo


Why Use It?

This plugin is designed to allow manipulation on elements depending on their visibility in the browser. It gives the developer the freedom to use their own CSS or JS to determine what happens; whether it's animation or a change in state. It leverages HTML5 data-* attributes instead of classes for ease and developer clarity. Emergence.js is one of the lightest and most compatible plugins of its kind.


Getting Started

Reference emergence.js just before your closing </body> tag, then simply call emergence.init.

<script src="path/to/emergence.min.js"></script>
<script>
  emergence.init();
</script>

Grab the latest code from the following locations:


How To Use

Add data-emergence="hidden" to any element you wish to watch:

<div class="element" data-emergence="hidden"></div>

When the element becomes visible within the viewport, the attribute will change to data-emergence="visible". Now you can leverage CSS, for example, to animate the element:

.element[data-emergence=hidden] {
  /* Hidden state */
}
.element[data-emergence=visible] {
  /* Visible state */
}

Custom Options

Emergence.js has a number of options you can customize. Below are the defaults:

emergence.init({
  container: window,
  reset: true,
  handheld: true,
  throttle: 250,
  elemCushion: 0.15,
  offsetTop: 0,
  offsetRight: 0,
  offsetBottom: 0,
  offsetLeft: 0,
  callback: function(element, state) {
    if (state === 'visible') {
      console.log('Element is visible.');
    } else if (state === 'reset') {
      console.log('Element is hidden with reset.');
    } else if (state === 'noreset') {
      console.log('Element is hidden with NO reset.');
    }
  }
});

Options Explained

container

By default, the visibility of elements will be determined by the window's viewport dimensions and X/Y scroll position (when set to window). However, it's possible to change it to a custom container. For example:

var customContainer = document.querySelector('.wrapper');

emergence.init({
  container: customContainer
});

throttle

Throttle is a method that prevents performance issues associated with scroll and resize events. The throttle will create a small timeout and steadily check element visibility every set amount of milliseconds during the event. The default is 250.

reset

Determines whether the data-attribute state will reset after it's been revealed. Set reset to false if you wish for the element to stay in its revealed state even after leaving the viewport. The default is true.

handheld

Emergence will do a check for most handheld device models such as phones and tablets. When set to false, the plugin will not run on those devices. The default is true.

elemCushion

The element cushion will determine how much of the element needs to be within the viewport to count as "visible". A value of 0.5 would equate to 50% of the element needing to be visible. The default is 0.15.

offsetTop, offsetRight, offsetBottom, offsetLeft

Provide an offset (in pixels) on any edge of the viewport. This is useful if you have a fixed component such as a header, for which you can offset the same value as the height of the header. A value of 100 applied to offsetTop will mean elements will only count as visible when they are greater than 100 pixels from the top of the viewport. The default for all is 0.

callback

Useful for providing callbacks to determine when an element is visible, hidden and reset. The possible states are visible, reset, and noreset.


Advanced

Engage

If you want to refire visibility checks outside of the load, scroll and resize events already baked into the plugin, use the following:

emergence.engage();

Disengage

If you want to disable Emergence, use the following:

emergence.disengage();

Browser Support

Emergence.js is dependent on the following browser APIs:


Issues & Contributions

Issues can be resolved quicker if they are descriptive and include both a minimal test case and a set of steps to reproduce.

While new features are welcome, any contributions that can fix bugs, maximize compatibility, and improve performance are preferred.


Release history

  • 1.1.2
    • Added handheld detection for Kindle Fire and PlayBook
    • Updated comments
    • Updated npm packages
    • Optimized animations on demo
    • Optimized responsive styles on demo
    • Added release history to README.md
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].