Szymon
Szymon

Reputation: 1290

Reach middle element on (window).scroll

I don't know what is going wrong? I was trying all to get the #second element when scroll

Here's example with console.log CODEPEN EXAMPLE

$(window).scroll(function(){
    var section     =     $("#second").offset().left,
    scrollXpos          =   $("body").scrollLeft();




    if(scrollXpos == section){

        console.log("second")
    }
    else{
         console.log("rest")
    }
});  

Upvotes: 0

Views: 186

Answers (1)

Szymon
Szymon

Reputation: 1290

Apparently opera , ie and firefox works better with

$(document).scrollLeft();

not

$("body").scrollLeft();

and same goes for

$(document, window).scroll(function(){

not

$(window).scroll(function(){

Thx @trendy

Upvotes: 1

Related Questions