Answers for "if element touches another element on scroll"

0

if element touches another element on scroll

$(window).scroll(function() {
    var div1 = $("#div1");
    var div2 = $("#div2");
    var div1_top = div1.offset().top;
    var div2_top = div2.offset().top;
    var div1_bottom = div1_top + div1.height();
    var div2_bottom = div2_top + div2.height();

    if (div1_bottom >= div2_top && div1_top < div2_bottom) {
        // overlapped
    }
});​
Posted by: Guest on August-10-2021

Code answers related to "if element touches another element on scroll"

Code answers related to "Javascript"

Browse Popular Code Answers by Language