if element touches another element on scroll

Solutions on MaxInterview for if element touches another element on scroll by the best coders in the world

showing results for - "if element touches another element on scroll"
Greta
31 Jul 2020
1$(window).scroll(function() {
2    var div1 = $("#div1");
3    var div2 = $("#div2");
4    var div1_top = div1.offset().top;
5    var div2_top = div2.offset().top;
6    var div1_bottom = div1_top + div1.height();
7    var div2_bottom = div2_top + div2.height();
8
9    if (div1_bottom >= div2_top && div1_top < div2_bottom) {
10        // overlapped
11    }
12});​
13