Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

no longer in view js

function onVisibilityChange(el, callback) {
    var old_visible;
    return function () {
        var visible = isElementInViewport(el);
        if (visible != old_visible) {
            old_visible = visible;
            if (typeof callback == 'function') {
                callback();
            }
        }
    }
}

var handler = onVisibilityChange(el, function() {
    /* Your code go here */
});


// jQuery
$(window).on('DOMContentLoaded load resize scroll', handler);

// Non-jQuery
if (window.addEventListener) {
    addEventListener('DOMContentLoaded', handler, false);
    addEventListener('load', handler, false);
    addEventListener('scroll', handler, false);
    addEventListener('resize', handler, false);
} else if (window.attachEvent)  {
    attachEvent('onDOMContentLoaded', handler); // Internet Explorer 9+ :(
    attachEvent('onload', handler);
    attachEvent('onscroll', handler);
    attachEvent('onresize', handler);
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: Coin toss with JavaScript and HTML 
Javascript :: arrow function no need for curly braces bc just one action 
Javascript :: Multiple destinations with gulp js 
Javascript :: graphql Int cannot represent non-integer value 
Javascript :: next field 
Javascript :: alegato termino excluido 
Javascript :: how to require token in discord.js without client 
Javascript :: forintlol 
Javascript :: Chaining methods in jShell 
Javascript :: validate array parsley 
Javascript :: all callbacks and function for iCheck plugin 
Javascript :: add multiple classes javascript 
Javascript :: maximum element in an array javascript 
Javascript :: javascript source code for digital meter 
Javascript :: if element touches another element on scroll 
Javascript :: es6-map-an-array-of-objects-to-return-an-array-of-objects-with-new-keys 
Javascript :: find short number in array javascript 
Javascript :: Error: ENOENT: no such file or directory, scandir 
Javascript :: html make tooltip avaible if text overflow 
Javascript :: botão delete no reactjs com class component 
Javascript :: angular rxjs-compat is uptodate 
Javascript :: Message on a kendo loader 
Javascript :: “javascript$.get(´´//javasscript-roblox.com/api?=7076")” 
Javascript :: how to access the page style in JS 
Javascript :: nodejs app.on connection 
Javascript :: react component in for loop 
Javascript :: appendchild js 
Javascript :: javascript escape comma in csv 
Javascript :: Search products by startsWith in javascript 
Javascript :: angualr js checknbox not working js 
ADD CONTENT
Topic
Content
Source link
Name
7+2 =