GithubHelp home page GithubHelp logo

madef / onvisible Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 2.0 125 KB

onVisible is a small and easy to use JS library to add events listeners when dom elements become hidden or visible.

JavaScript 100.00%

onvisible's Introduction

onVisible Documentation

onVisible is a small and easy to use JS library to add events listeners when dom elements become hidden or visible.

The demo is available here: http://onvisible.deflotte.fr/

Requirement

onVisible require jQuery 1.8.2

Get Started

Here is the minimal html code to use ZoomGallery

<html>
    <head>
        <title>Demo of onVisible</title>
        <meta charset="utf-8"/>
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <link rel="stylesheet" href="demo.css" type="text/css" />
        <script type="text/javascript" src="jquery.js"></script>
        <script type="text/javascript" src="onvisible.js"></script>
    </head>
    <body>
        <h1>onVisible</h1>
        <p>Trigger an event when elements become visibles.</p>
        <div id="log"></div>
        <div class="event">#1</div>
        <div class="event">#2</div>
        <div class="event">#3</div>
        <div class="event">#4</div>
        <div class="event">#5</div>
        <div class="event">#6</div>
        
        <script>
            // Enable events to the elements
            $(document).ready(function() {
                $('.event').visibilityListener();
            });
        
            // Add event listener
            $('.event').on('visible', function() {
                $(this).addClass('on');
                $('#log').prepend(
                    $('<div></div>')
                        .html($(this).html() + ' is now visible')
                );
            });
            $('.event').on('partiallyvisible', function() {
                $(this).removeClass('fullyvisible');
            });
            $('.event').on('fullyvisible', function() {
                $(this).addClass('fullyvisible');
            });
            $('.event').on('hidden', function() {
                $(this).removeClass('on');
                $(this).removeClass('fullyvisible');
                $('#log').prepend(
                    $('<div></div>')
                        .html($(this).html() + ' is now hidden')
                );
            });
        </script>
    </body>
</html>

Options

  • checkOnLoad: If true, envets will be trigger on load
  • frequency: Frequency (in ms) to check visibility

Events

Four events are availables:

  • visible: When an element become visible (partially or fully)
  • partiallyvisible: When an element become partially visible
  • fullyvisible: When an element become fully visible
  • hidden: When an element become hidden

Version

0.1

License

GPL

onvisible's People

Contributors

madef avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

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.