views:

72

answers:

2

Can't find a simple solution to this, I know it's easy and I've tried a few things but I can't quite get it to work. I'm currently working with a sidescrolling site and I want every time you click an image (contained in an li) it scrolls to the next li. I have jQuery plugin localscroll so it smoothly goes from one to the next, and that's working. I need to now write a code that triggers jQuery to utilize the localscroll function and go to the next li. Right now I have this, but I know it's not right:

$(document).ready(function () {
    $('.wrapper ul li').click(function() {
     $(this).next(li).localScroll();
    });
});
A: 

After reading the documentation for this here, I figured out the correct of way of using it. Let us say, you the .wrapper element as the one overflowing or in which you want to scroll. You can do the following.

$(document).ready(function () {
    var gallery = $('.wrapper ul li')

    $(gallery).click(function() {
           $('.wrapper').localScroll({
              target:$(this).next('li')
            });

    });
});
mohang
Hm... didn't seem to have any effect. I'll upload a demo
steve
Here's the demo: http://www.studioimbrue.com/sites/eliotdudik
steve
A: 

Accoding to the ScrollTo examples, you need to do this:

$(container).scrollTo(element);

e.g.

$(document).ready(function () {
    $('.wrapper ul li').click(function() {
        $(window).scrollTo($(this).next('li'));
    });
});
strager
Just uploaded a demo with that code, it doesn't function either.
steve
the demo is at the same as below, http://www.studioimbrue.com/sites/eliotdudik
steve
@steve, It seems like your click handler isn't being called. That could be why you're not seeing any results. =]
strager
@steve, You are trying to reference `#wrapper` using `.wrapper`.
strager
Ah, excellent, problem fixed. The only problem now is that it jumps to the next instead of sliding to it.. is that because I'm calling scrollTo and not localScroll?
steve
Fixed it! I just added the time and easing parameters to the .scrollTo() function above. Thanks.
steve