views:

32

answers:

1

Hey i want to use jquery UI to have a slider on my page that moves multiple divs different distances.

So basically you pull the slider and div1 moves 10px left and div2 moves 20px left.

I have taken a look at the jquery UI slider here http://jqueryui.com/demos/slider/#side-scroll but i cant figure out how to get that slider to move multiple divs.

Help would be greatly appreciates. I am pretty new to jquery but i am enjoying the learning experience =]

+1  A: 

You can use the .slide() event, no? http://jqueryui.com/demos/slider/#event-slide

That way you can adjust the divs like you want. I'll write a little example

Made a small example: http://labs.joggink.be/slider-multiple-divs/

The slider resizes 3 divs like this (it's very basic and ugly written):

        $("#slider").slider(
            {
                        value:100,
                        min: 10,
                        max: 250,
                        step: 10,
                        slide: function(event, ui) {
                            $('#div-1').css({
                                width : ui.value + 'px',
                                height: ui.value + 'px'
                            });
                            $('#div-2').css({
                                width : ui.value + 10 + 'px',
                                height: ui.value + 10 + 'px'
                            });
                            $('#div-3').css({
                                width : ui.value + 20 + 'px',
                                height: ui.value + 20 + 'px'
                            });
                        }
            });
    });
joggink
Thanks a bunch. I prefer the one with the resizing bar though. Currently i have the two divs being moved by the slider but i need the one to move at a different speed. A example would be great thanks!
salmon
So, use the code above but change the positions, instead of the sizes - job done.
belugabob
Thanks alot for the example =] Ok here is a link to what i have so far, i cant manage to get the bottom boxes to scroll at a different speed to the top ones. http://www.ehbeat.com/test2/slider.htmlIdeally, when you drag the slider from the left to the right i want the top and bottom boxes to move at different speeds so that when the slider gets to the right the boxes that say 20 and 10 are lined up.Thanks alot for the help and sorry if i am being a little confusing.
salmon
In the code you are adjusting the scrollContent margin left, but the scrollContent contains both your divs, so the adjustment is the same. You have to create a second scrollContent where you adjust the margin-left with half the speed of the ui.value. Then the bottom line of divs will move half as fast as the top line giving you the eventual result of div 20 and div 10 lined up.
joggink