CSS-Tricks / MovingBoxes

Simple horizontal slider which grows up the current box when it's in focus (image, title & text) and back down when it's not in focus.
http://css-tricks.github.io/MovingBoxes/
GNU Lesser General Public License v3.0
280 stars 147 forks source link

Make 100% width #27

Closed Mottie closed 12 years ago

Mottie commented 13 years ago

Adding a request to make MovingBoxes fill 100% browser width. Or as cbarnes0981 stated, fill 100% of it's container.

chrisbarnes commented 13 years ago

It would be great if you could just make the slider take up 100% of the container it's put in. The equivalent of max-width: 100%;

jalbert33 commented 13 years ago

I got the same need. Would be great ;)

brigleb commented 13 years ago

Same here. May give it a shot myself, if I have time.

Mottie commented 13 years ago

I was trying to think this out... if the slider takes up 100% width of the container it is in, how do I adjust the height?

Do we completely ignore the panelWidth option? If I don't, the the panel will take up 50% of the width and thus adjust the height making the panel much much taller. Or should we have a set maximum height, center the current panel and not worry about how many other panels are showing on either side?

kaushal123 commented 13 years ago

Has any one solved this issue?

Mottie commented 13 years ago

Not yet! :(

Mottie commented 12 years ago

Ok, this should now be possible. Here is a demo of how to use the window resize function to update MovingBoxes.

The resize will only work if you set the width and panelWidth options before calling the update function. These options were deprecated, but I think using them before calling the update is the easiest method to change the size.

Notes:

Here is a demo of making MovingBoxes work with a percentage width, the resize event is automatically throttled:

// This resize demo only works properly with MovingBoxes v2.2.3+
var timer;
$(window).resize(function(){
    clearTimeout(timer);
    var slider = $('#slider').data('movingBoxes');
    slider.options.width = $(window).width() * 0.5; // make 50% browser width
    slider.options.panelWidth = 0.7; // make 70% of wrapper width
    // prevent updating continuously, aka throttle resize
    timer = setTimeout(function(){
        slider.update(false);
    }, 100);
});
centinex commented 12 years ago

Hi Mottie and thanks for maintaining this very usefull and classy plug in. I'm using it with this resize, (chopped from the timer, so my template always looks good even while dragging the windows. I know, it's painful for the browser, but it do looks really good). Anyway, I don't know why but at first page load, MovingBoxes is not sized to it's correct percentage, but fills the current container. It only gets it's correct size when window get resized. I haven't spent too much time tracking why (as resizing do works perfectly on a blank test page), and it maybe be my fault due to a crowded template (there are more than one slider on a single page, for starter) and maybe some not-so-clean JS somewhere else, but I have devised this quick and dirty fix :


window.onload = function()
            {
            var slider = $('#slider1').data('movingBoxes');
            slider.options.width = $(window).width() * 0.55; // 0.5 make 50% browser width
            slider.options.panelWidth = 0.4; // 0.7 make 70% of wrapper width
            }

Maybe it can help someone with this issue.