views:

74

answers:

3

Hi, I've been trying to recreate an effect from this tutorial: http://jqueryfordesigners.com/jquery-look-tim-van-damme/

Unfortunately, I want a background image underneath and because of the resize going on in JavaScript, it gets resized and cut off as well, like so: http://dev.gentlecode.net/dotme/index-sample.html - you can view source there to check the HTML, but basic structure looks like this:

<div class="page">
     <div class="container">
         div.header
         ul.nav
         div.main     
     </div> 
</div> 

Here is my jQuery code:

$('ul.nav').each(function() {
    var $links = $(this).find('a'),
        panelIds = $links.map(function() { return this.hash; }).get().join(","),
        $panels = $(panelIds),
        $panelWrapper = $panels.filter(':first').parent(),
        delay = 500;

    $panels.hide();

    $links.click(function() {
        var $link = $(this),
            link = (this);

        if ($link.is('.current')) {
            return;
        }

        $links.removeClass('current');
        $link.addClass('current');

        $panels.animate({ opacity : 0 }, delay);
        $panelWrapper.animate({
            height: 0
        }, delay, function() {
            var height = $panels.hide().filter(link.hash).show().css('opacity', 1).outerHeight();

            $panelWrapper.animate({
                height: height
            }, delay);
        }); 
    });

    var showtab = window.location.hash ? '[hash=' + window.location.hash + ']' : ':first';

    $links.filter(showtab).click();

});

In this example, panelWrapper is a div.main and it gets resized to fit the content of tabs. The background is applied to the div.page but because its child is getting resized, it resizes as well, cutting off the background image.

It's hard to explain so please look at the link above to see what I mean.

I guess what I'm trying to ask is: is there a way to resize an element without resizing its parent? I tried setting height and min-height of .page to 100% and 101% but that didn't work. I tried making the background image fixed, but nada. It also happens if I add the background to the body or even html. Help?

A: 

Have you tried adding min-height: 100%; background-attachment: fixed; to the body element?

The background-attachment might not be needed, though.

David Thomas
I tried it both on body and .page (where the background actually is, body has different background) - didn't work.
Justine
A: 

Could you add the background image to the body instead of the .page element?

.page {
background: transparent url(../img/glass/bg-page.png) top center fixed no-repeat;
overflow: hidden;
}

The body fills the browser window but the .page div is only as big as its content, which is why it's getting cut off as the content animates.

prendio2
"It also happens if I add the background to the body or even html." EDIT: Actually, when I add the bubbles background to html, it's okay. Problem is, there is another background layer (the gradient) that is supposed to be underneath and so I can't really add it to html element.
Justine
Since the gradient background on the `body` isn't getting cut off, I don't see how the bubbles background could be.CSS3 allows for multiple background images as detailed here http://www.w3.org/TR/css3-background/#layering
prendio2
You can view it here: http://dev.gentlecode.net/dotme/index-body.html - gradient is set on `html` element, bubbles on `body` and it still cuts them off.
Justine
+1  A: 

Another solution could be to use jquery to set a minimum height on the .page element. Height must be set in pixels, not percentages. I've tested the following and it works:

$('.page').css('min-height',$('body').height()+'px');

But you will need to run this whenever the browser window is resized.

For a completely non-javascript solution you could put the bubbles in an absolutely positioned div behind the content. Use the following CSS to make the div fill the screen:

position:absolute;
left:0px;
right:0px;
top:0px;
bottom:0px;
z-index:1;

You'll have to make sure this doesn't sit on top of your page content by giving that a higher z-index (for z-index to take effect you will need to set position:relative or position:absolute on the page content)

prendio2
The jQuery minimum height thing worked like a charm, and it still works after resizing window. I will test it around and either use this or the absolutely positioned div, totally didn't think of that, thanks!
Justine