0

I've this function:

$(function() {
$(window).scroll(function(e) {
    var sl = $(this).scrollLeft();
    var lbl = $("#waypoints");
    if (sl > 0) {
        lbl.show('');
    }
    else {
        lbl.hide();
    }
    if (sl > 750) {
        lbl.html("<p>now passed 750</p>");
    }
    if (sl > 1000) {
        lbl.html("<p>now passed 1000</p>");
    }
});

});

Which work when i scroll the browser window. But I need to adjust it, so that it is set for a div (#main) which scrolls inside another div (.content) which has a fixed width and css overflow enabled.

I've tried $(#main).scroll(function(e) { no joy ...

thanks for reading, any help would be awesome.

3
  • It's suppose to be scrolled vertically? Commented Sep 3, 2012 at 12:18
  • Can you post some HTML or a Fiddle? Commented Sep 3, 2012 at 12:19
  • Guess you are only missing apostrophes $('#main').scroll(... seems 2 b an easy fix. And also you can reorder it to this: if (sl > 1000) {...} else if (sl > 750) {...} to prevent that double overwritting ;-) Commented Sep 3, 2012 at 12:23

2 Answers 2

1

Try to change to class:

$(function() {
    $('.content').scroll(function(e) {
        var sl = $(this).scrollLeft();
        var lbl = $("#waypoints");
        if (sl > 0) {
            lbl.show();
        }
        else {
            lbl.hide();
        }
        if (sl > 750) {
            lbl.html("<p>now passed 750</p>");
        }
        if (sl > 1000) {
            lbl.html("<p>now passed 1000</p>");
        }
    });
});​

Here's a JSFiddle

Sign up to request clarification or add additional context in comments.

Comments

0

I don't see what's the problem here - it's working (I mean the scroll events are fired, as you can see by scrollLeft value that is changing) http://jsfiddle.net/DTKeX/2/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.