Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to determin if element is in viewport with jquery

// this function runs every time you are scrolling

$(window).scroll(function() {
    var top_of_element = $("#element").offset().top;
    var bottom_of_element = $("#element").offset().top + $("#element").outerHeight();
    var bottom_of_screen = $(window).scrollTop() + $(window).innerHeight();
    var top_of_screen = $(window).scrollTop();

    if ((bottom_of_screen > top_of_element) && (top_of_screen < bottom_of_element)){
        // the element is visible, do something
    } else {
        // the element is not visible, do something else
    }
});
Comment

how to determin if element is in viewport with jquery

$.fn.isInViewport = function() {
    var elementTop = $(this).offset().top;
    var elementBottom = elementTop + $(this).outerHeight();

    var viewportTop = $(window).scrollTop();
    var viewportBottom = viewportTop + $(window).height();

    return elementBottom > viewportTop && elementTop < viewportBottom;
};
Comment

PREVIOUS NEXT
Code Example
Javascript :: unable to locate package npm 
Javascript :: setup ejs views directory in express 
Javascript :: regex to extract valid http or https 
Javascript :: js hide element by class 
Javascript :: isogram javascript 
Javascript :: math rock 
Javascript :: jquery get attribute value of parent element 
Javascript :: remove unused dependencies React 
Javascript :: flutter decoration image 
Javascript :: selectpicker append option 
Javascript :: a JavaScript function to multiply a set of numbers 
Javascript :: why is the radiators in cars painted black 
Javascript :: react-bootstrap nextjs 
Javascript :: console.dir depth 
Javascript :: display loader on ajax call 
Javascript :: electron specify minimum size 
Javascript :: how to check element is in viewport 
Javascript :: enable native bracket matching vs cide 
Javascript :: javascript get unique values from array 
Javascript :: javascript enable a button once an input text filled 
Javascript :: onclick cloSe tab in jquery 
Javascript :: how to add keyboard shortcuts javascript 
Javascript :: js get array item by property 
Javascript :: js time difference in minutes 
Javascript :: alphabetical order array javascript 
Javascript :: javascript loop through string 
Javascript :: length of elements with display none 
Javascript :: input type text js 
Javascript :: loop over javascript using foreach 
Javascript :: leaflet change zoom button position 
ADD CONTENT
Topic
Content
Source link
Name
5+1 =