Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

add class when element in viewport vanilla javascript

window.addEventListener('scroll', function (event) {
    if (isInViewport(theElementToWatch)) {
      // update the element display
    }
}, false);
Comment

add class when element in viewport vanilla javascript

function isInViewPort(element) {
    // Get the bounding client rectangle position in the viewport
    var bounding = element.getBoundingClientRect();

    // Checking part. Here the code checks if it's *fully* visible
    // Edit this part if you just want a partial visibility
    if (
        bounding.top >= 0 &&
        bounding.left >= 0 &&
        bounding.right <= (window.innerWidth || document.documentElement.clientWidth) &&
        bounding.bottom <= (window.innerHeight || document.documentElement.clientHeight)
    ) {
        console.log('In the viewport! :)');
        return true;
    } else {
        console.log('Not in the viewport. :(');
        return false;
    }
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: postmessage from iframe to parent 
Javascript :: alpine in laravel mix 
Javascript :: js function pick properties from object 
Javascript :: Codewars JS Multiples of 3 or 5 
Javascript :: get placeholder innerhtml 
Javascript :: getboundingclientrect() javascript 
Javascript :: avascript sum of arguments 
Javascript :: like knex 
Javascript :: react autocomplete off for password chrome 
Javascript :: how to fix Composer could not find a composer.json file in Z:xampp 7312htdocsproject_karakter-master 
Javascript :: perform database transaction with sequelize 
Javascript :: fetch javascript 
Javascript :: how to make a deep copy in javascript 
Javascript :: how to specify max number of character angular mat input 
Javascript :: jquery set att 
Javascript :: json array to string in postgresql 
Javascript :: a function that calls itself js 
Javascript :: javascript add line from file to array 
Javascript :: semantic ui dropdown value 
Javascript :: js remove null from array 
Javascript :: validate password regex 
Javascript :: javascript create range with a loop 
Javascript :: column.footer jquery 
Javascript :: compare two dates using moment 
Javascript :: javascript split multiple delimiters 
Javascript :: javascript regex check phone number 
Javascript :: sort object by key value js 
Javascript :: https://mongoosejs.com/docs/deprecations.html#findandmodify 
Javascript :: slickcdn 
Javascript :: show hide more text jquery 
ADD CONTENT
Topic
Content
Source link
Name
6+8 =