views:

49

answers:

1

Hi there,

I'm having a terrific problem with an implementation of serialscroll. I've set it so that each list item is 100% width, to get a full screen slideshow going.

You can check out the full code here: http://www.reverenddan.net/so/

The CSS is fairly simple:

#slideshow {
width: 100%;
height:100%;
margin: 0;
padding: 0;
position:absolute;
overflow:hidden;
}

#slideshow ul {
width: 800%;
height:100%;
margin: 0;
padding:0;
}

#slideshow li {
width:12.5%;
height:100%;
margin: 0;
padding: 0;
float:left;
list-style: none;
}

and the corresponding HTML:

<div id="slideshow">
                <ul>
                    <li id="slide1"><img class="centered" src="img/beetle.png" width="344" height="380" /></li>
                    <li id="slide2"><img class="centered" src="img/beetle.png" width="344" height="380" /></li>
                    <li id="slide3"><img class="centered" src="img/beetle.png" width="344" height="380" /></li>
                </ul>
            </div>

It's all working a treat, however if you resize the window on the second or third frames, the list items holding the images seem to resize at a different rate than the browser window, rather than staying centered. I've used a bit of jquery to vertically align the images, but I thought the text-align: center and 100% width would be enough to keep them in place.

Any thoughts would be greatly appreciated, I'm at the end of my tether!

+1  A: 

Try changing #slideshow to use a fixed width, relative positioning, and an automatic left and right margin, which should have the effect of centering it (and its content):

#slideshow{
  position: relative;
  height: 100%;
  width: 900px;
  margin: 0 auto;
  padding: 0;
  overflow:hidden;
}

Change the 900px width I suggest above to something smaller if you're not going to be using images that wide.

NickD
I could kiss you! Thank you so much. As a sidenote: Changing from absolute to relative meant the 100% height no longer worked which killed my vertical alignment. I added in a line of jquery to resize the #content div to the window height and it's all working beautifully now!Thanks again
Dan
Glad it helped. Good point about the 100% height -- pleased you were able to compensate for it with jQuery.
NickD
Not sure if you'll see this but I have a quick follow-up question. The only niggle I have with the solution is that now the images don't slide in using the full window width (obviously) - I had some nice png overlays on the edge of the screen that you can see in the demo. I just don't understand why making the list items 100% width (or using js to set a pixel width the same size as the window) screws up so badly. Is there no way to achieve this, or am I asking to have my cake and eat it? Cheers
Dan
You could set the width of the #slideshow to the window width using JavaScript -- just be sure that you set the width to the new window width every time the user resizes the window. You could bind the window's resize event and use a timer to achieve this: http://snipplr.com/view/6284/jquery--window-on-resize-event/
NickD
I did try this but unfortunately it had exactly the same effect as width:100%; - I've updated the demo with the new js code, but I've a feeling this may be a lost cause. Thanks again for all your help!
Dan
Backtracking a little, how about removing the JavaScript code that resizes #slideshow's width, setting the #slideshow to a fixed width of 900px again in the CSS as before, and then removing the 'overflow:hidden;' property of #slideshow (or changing it to overflow:visible)? My thinking is that the images might then show through all the way to the edge of the window, even though the parent box is only 900px wide. Untested, but thought I'd share the idea anyway.
NickD
I gave it ago but the overflow:hidden is needed for the serialscroll to function. In the end I managed to semi-fix it by calling the scroll function again on resize. It's ugly, but it does the trick.
Dan