Alexandru Vlas
Alexandru Vlas

Reputation: 1415

jQuery check if DIV (not window) started scrolling and addClass to another div

I have my "html" setted at overflow hidden (no scrollbar), but I have my contentarea div (where all the content is) that is scrollable and has a scrollbar...

What I'm trying to do is if user starts scrolling in the contentarea addClass (jquery) to another div.. if user scroll all the way to the top removeClass...

Here is the code I have that was working fine before I made the "html" overflow hidden..

jQuery(window).scroll(function() {
if (jQuery(this).scrollTop() == 0) {
    jQuery("#jQ").removeClass("scroll_active");
}
else {
    jQuery("#jQ").addClass("scroll_active");
}
});

I tried to put the contentarea id instead of window.. something like this:

jQuery(#contentarea).scroll(function() {
if (jQuery(this).scrollTop() == 0) {
    jQuery("#jQ").removeClass("scroll_active");
}
else {
    jQuery("#jQ").addClass("scroll_active");
}
});

but it still doesn't work...

http://jsfiddle.net/erxw5/

Can somebody give me a hand please, I tried everything I can already... Thank you very much

Upvotes: 0

Views: 320

Answers (1)

Hamza Kubba
Hamza Kubba

Reputation: 2269

  1. You can use $() instead of jQuery(). jQuery() works but it's unnecessary.
  2. You should use $('#contentarea') or jQuery('#contentarea') instead of jQuery(#contentarea), because you need quotes there. window is an object that exists. #contentarea is a string.

ALL MY FIXES TOGETHER: http://jsfiddle.net/mw3H8/1/

Upvotes: 1

Related Questions