w1l
w1l

Reputation: 157

Javascript parameter help needed

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.

Upvotes: 0

Views: 60

Answers (2)

Mihai Iorga
Mihai Iorga

Reputation: 39724

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

Upvotes: 1

WTK
WTK

Reputation: 16981

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/

Upvotes: 0

Related Questions