Giter Site home page Giter Site logo

creativelive / appear Goto Github PK

View Code? Open in Web Editor NEW
177.0 32.0 43.0 2.14 MB

execute callbacks when dom elements appear in and out of view

Home Page: http://creativelive.github.io/appear/

License: MIT License

JavaScript 40.54% HTML 59.46%
dom-element javascript scrolling

appear's Introduction

appear appear

Track the visibility of dom elements and fire user defined callbacks as they appear and disappear.

Demos

Be sure to view the documentation on the project page

Usage

Include appear.js in your page, it has no dependencies.

Call appear() passing in an object with the following:

  • init function to run when dom is interactive, but before appear.js has started tracking.
  • elements required function that returns an htmlcollection of elements to track. The dom will be interactive at this point. Can alternatively be an existing htmlcollection instead of a function.
  • appear function to run when an element is in view, passed the element that has come into view. If defined then appear.js will track elements until they come into view.
  • disappear function to run when an element goes out of view, passed the element that has gone out of view. If defined then appear.js will track elements until they go out of view.
  • reappear if true appear.js will keep tracking elements for successive appears and dissappears. Default is false.
  • bounds increase, in pixels, to the threshold size of the element so it can be "viewable" before it is actually in the viewport.
  • debounce appear.js tracks elements on browser scroll and resize, for performance reasons this check is "debounced" to only happen once for multiple events, 50ms after the last event ends. You can override this value here.
  • deltaSpeed in addition to debouncing, appear.js will also check for items during continuous slow scrolling, you can controll how slow the scrolling should be via this value. Default is 50 (pixels).
  • deltaTimeout after a succesful delta speed check, appear.js will not check for viewable items again until this timeout passes. Default is 500 (ms).
  • done function called when appear.js is no longer tracking any items and event listeners have been removed.

Example

appear({
  init: function init(){
    console.log('dom is ready');
  },
  elements: function elements(){
    // work with all elements with the class "track"
    return document.getElementsByClassName('track');
  },
  appear: function appear(el){
    console.log('visible', el);
  },
  disappear: function disappear(el){
    console.log('no longer visible', el);
  },
  bounds: 200,
  reappear: true
});

api

appear() will return an object with the following:

  • trigger() force a check for viewable elements.
  • pause() temporarily stop tracking elements.
  • resume() resume tracking elements.
  • destroy() permanently stop tracking elements.

Download

source or minified


appear.js logo designed by Magicon from the Noun Project :: Creative Commons - Attribution (CC BY 3.0)

appear's People

Contributors

aliwatters avatar audiovoyeur avatar dzoba avatar jimmybyrum avatar justinbeaudry avatar leggsimon avatar matthewhadley avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

appear's Issues

Hidden elements trigger appear

I have a hidden element (display:none) that's way below the fold.
Although the element is not in the view-port appear is triggered on page load.

Calling getBoundingClientRect():
image

I think, that appear should not be fired for hidden elements.

appear.js in bower.io

Hello guys,

I love this appear version, the way appear {} is takin place
My issue is just one, i would like to download appear.js from bower.io
I found there to many appears type fr ex jquery.appear, but i am not finding this version

Does it exist there in bower.io ? Can you guys upload it there ?

Many thanks,
king regards

Minimum screen width ?

Hello,

Is there a minimum screen width needed to use appear ?
When my screen width is under 495px, appear and disappear functions aren't launched, is it normal ?

Appear not defined

Hi,

We were using an earlier version of appear.js (1.0.3) and we were able to use it fine (called it using the sample code you provided on your website, appear({object content here})).
I tried a new project with the latest version and I am getting "appear is not defined" error inside Console. Do we need to assign it to a variable or another object and then execute it? Or does it has something to do with module imports/exports? Sorry, i'm not the most experienced person with JS but just noticed this and wanted to know if it had something to do with the way I was calling it or not.

Thanks

Please update version in npm

Hi,
I would like to use npm but I realised that the npm copy of this library is out-of-date 1.0.1 while the latest version that I can download from Github is 1.2.1.
Thanks

Not capturing live added elements

As you know, elements is captured on init time (documentReady).

 elements: function elements(){
    // work with all elements with the class "track"
    return document.getElementsByClassName('gptAds');
  }

captures all elements with class gptAds, if I add new elements with that class, they are not tracked by appear

Disappear is never called

I don't get why this configuration of appear.js doesn't fire the disappear event. I only see appear to be called.

window.appear({
            init: function init() {
                console.log("init");
            },
            elements: function elements() {
                let rowGroups = document.getElementsByClassName("row-group");
                console.log("Tracking #: " + rowGroups.length);
                return rowGroups;
            },
            appear: function appear(group) {
                cmp.getEvent("loadRowGroup")
                    .setParams({ data: group.id })
                    .fire();
            },
            disappear: function disappear(group) {
                cmp.getEvent("unloadRowGroup")
                    .setParams({ data: group.id })
                    .fire();
            },
            bounds: 200,
            reappear: true
        });

Does it have to do with how my DOM looks like? When I don't scroll it just show a single . Appear() is called once. But when I just scroll a few pixels for ALL the other elements appear() is called. Without them being visible.

appear doesn't load in webpack

When requiring appear in a webpack-bundled file, it doesn't appear as a function.

Adding 'module.exports = appear;' to the end of appear.js fixes this problem, but I don't know if this would break the plugin for someone using it normally. Thoughts?

ability to set target scrollable container

is there a way to set the target scrollable container? Eg let say i have a div(#sample) that contains elements (images). div#sample is static in the viewport but it content is scrollable. on scroll in div#sample can appear.js; appear/disappear/reappear/etc functions can be run/use

<ie9 support?

Currently we're using window.addEventListener in this project. To support older versions of IE (<IE9) we should use a function like:

function addListener (eventType, cb) {
  if (addEventListener) {
    addEventListener(eventType, cb, false); 
  } else if (attachEvent)  {
    attachEvent(eventType, cb);
  }
}

function removeListener (eventType, cb) {
  if (removeEventListener) {
    removeEventListener(eventType, cb, false); 
  } else if (removeEvent)  {
    removeEvent(eventType, cb);
  }
}

NPM module

I tried to use appear.js in a Meteor project via an NPM import (require('appear')) but there is no main specifier in package.json, so it won't load directly. I also tried require('appear/lib/appear') (also reasonable) but this file does not behave like a module with a default export of the appear function (nor do any of the dist versions), so it seems that there's no reasonable module entrypoint for appear.js. I imagine this wouldn't be too much effort to fix; would this be of interest as a PR?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.