4

I'm having some trouble with triggering a scroll event by using jquery.mousewheel. I want to "expand" the scroll event for #bio-content-container to trigger when scrolling over #bio-slider-container. I'm using following code:

var lastScrollTop = 0;      
$("#bio-content-container").scroll(function () {
    var st = $(this).scrollTop();
    if (st > lastScrollTop){
        scroll('Down');
    } else {
        scroll('Up');
    }
    lastScrollTop = st;
});

jQuery(function($) {
    $('#bio-slider-container')
        .bind('mousewheel', function(event, delta) {
            $("#bio-content-container").trigger('scroll');
            return false;
    });
});

I don't want to trigger scroll on #bio-slider-container, so that's why I'm using mousewheel. Any help would be much appreciated :)

1 Answer 1

3

If I understand correctly, you want to scroll the contents of #bio-content-container when you use the mousewheel over #bio-slider-container. You might want to check out the jquery.scrollTo plugin. This code works for me (without seeing your HTML):

$(document).ready(function () {

    $('#bio-slider-container').bind('mousewheel', function (event, delta) {
        var content = $("#bio-content-container");
        if (delta < 0) {
            content.scrollTo("+=10");
        } else {
            content.scrollTo("-=10");
        }
    });

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

3 Comments

Thanks, I was actually using scrollTo in a function to do some other thing, but i didn't think of this one. Anyway, is there a way to trigger a scroll event (e.g by clicking on a button..)?
Sure, $('#btnScrollDown').on('click', function () { $("#bio-content-container").scrollTo("+=10"); });
That's not exactly what I have in mind. I need to trigger default .scroll() event, not .scrollTo(). I'm using .scroll() on #bio-content-container with nice easing. .scrollTo() doesn't look so nice even with easing. With use of scrollTo("+=10") it looks a bit laggy.

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.