Help setting Width of Slides

Thanks for the help Paul.

Your solution does work, but adds a strange side-effect…

When the slide-show goes from Slide #1 to Slide #2, SLide #2 zooms by twice! (Same for Slide #3)

It is kind of a dizzying effect for readers.

I changed the transition settings in slideshow.js to make this side-effect more evident.

Just point to this file instead, and you’ll see what I mean…


$slideshow = {
    context: false,
    tabs: false,
    timeout: 5000,      // time before next slide appears (in ms)
//    timeout: 1000,      // time before next slide appears (in ms)
    slideSpeed: 5000,   // time it takes to slide in each slide (in ms)
//    slideSpeed: 1000,   // time it takes to slide in each slide (in ms)
    tabSpeed: 400,      // time it takes to slide in each slide (in ms) when clicking through tabs
    fx: 'scrollRight',   // the slide effect to use
//    fx: 'scrollLeft',   // the slide effect to use
//    fx: 'fade',   // the slide effect to use

    init: function() {
        // set the context to help speed up selectors/improve performance
        this.context = $('#slideshow');

        // set tabs to current hard coded navigation items
        this.tabs = $('ul.slides-nav li', this.context);

        // remove hard coded navigation items from DOM
        // because they aren't hooked up to jQuery cycle
        this.tabs.remove();

        // prepare slideshow and jQuery cycle tabs
        this.prepareSlideshow();
    },

    prepareSlideshow: function() {
        // initialise the jquery cycle plugin -
        // for information on the options set below go to:
        // [JQuery Cycle Plugin - Option Reference](http://malsup.com/jquery/cycle/options.html)
        $("div.slides > ul", $slideshow.context).cycle({
            fx: $slideshow.fx,
            timeout: $slideshow.timeout,
            speed: $slideshow.slideSpeed,
            fastOnEvent: $slideshow.tabSpeed,
            pager: $("ul.slides-nav", $slideshow.context),
            pagerAnchorBuilder: $slideshow.prepareTabs,
            before: $slideshow.activateTab,
            pauseOnPagerHover: true,
            pause: true
        });
    },

    prepareTabs: function(i, slide) {
        // return markup from hardcoded tabs for use as jQuery cycle tabs
        // (attaches necessary jQuery cycle events to tabs)
        return $slideshow.tabs.eq(i);
    },

    activateTab: function(currentSlide, nextSlide) {
        // get the active tab
        var activeTab = $('a[href="#' + nextSlide.id + '"]', $slideshow.context);

        // if there is an active tab
        if(activeTab.length) {
            // remove active styling from all other tabs
            $slideshow.tabs.removeClass('on');

            // add active styling to active button
            activeTab.parent().addClass('on');
        }
    }
};


$(function() {
    // initialise the slideshow when the DOM is ready
    $slideshow.init();
});


$('#s1').cycle({timeout:2000});

$('#pauseButton').click(function() {
    $('#s1').cycle('pause');
});

I agree that the problem really needs to be resolved in the JavaScript file. (It would be nice if the JavaScript Forum wouldn’t keep throwing this back on to the CSS side. Different levels of support I guess…) :rolleyes:

I was hoping to get some help on the JQuery forums, but I cannot register at their website and the author of the code won’t help me figure out why I can’t sign up?! :frowning:

Will have to kick around my version, Rayzur’s versions, and your version and see which makes the most sense?!

Maybe I was looking in the wrong JavaScript file, but when I looked in jquery.cycle.all.min.js it looked like “spaghetti code” and not knowing JavaScript, I certainly didn’t see any clear areas or variables that would help fix this problem.

I did see some “widths”, but don’t see where the data is coming in from or how it is being manipulated. Once again showing that “good code” is “documented code”!!! (Now we know why JavaScript programmers get such a bad wrap among other developers! Anyways…) :wink:

Debbie

Would it help if the scripting did not resize things?

jQuery’s Cycle plugin has an option called ‘containerResize’ which allows you to disable the resizing that you saw earlier.

So in the slideshow script where there was:


    prepareSlideshow: function() {
        // initialise the jquery cycle plugin -
        // for information on the options set below go to:
        // http://malsup.com/jquery/cycle/options.html
        $("div.slides > ul", $slideshow.context).cycle({
            fx: $slideshow.fx,
            timeout: $slideshow.timeout,
            speed: $slideshow.slideSpeed,
            fastOnEvent: $slideshow.tabSpeed,
            pager: $("ul.slides-nav", $slideshow.context),
            pagerAnchorBuilder: $slideshow.prepareTabs,
            before: $slideshow.activateTab,
            pauseOnPagerHover: true,
            pause: true,
            containerResize: false
        });
    },

There would now be the piece added in green:



    prepareSlideshow: function() {
        // initialise the jquery cycle plugin -
        // for information on the options set below go to:
        // http://malsup.com/jquery/cycle/options.html
        $("div.slides > ul", $slideshow.context).cycle({
            fx: $slideshow.fx,
            timeout: $slideshow.timeout,
            speed: $slideshow.slideSpeed,
            fastOnEvent: $slideshow.tabSpeed,
            pager: $("ul.slides-nav", $slideshow.context),
            pagerAnchorBuilder: $slideshow.prepareTabs,
            before: $slideshow.activateTab,
            pauseOnPagerHover: true,
            pause: true[color="green"],
            containerResize: false[/color]
        });
    },

That removes the resizing that scripting does, but now introduces more CSS issues, such as needing to set the height of the slides ul element to be able to see the content

I’d swing toward this plugin rather than Cycle. It’s simple and generates no inline style widths so should respect CSS applied to content.

jShowOff: a jQuery Content Rotator Plugin by Erik Kallevig

Hi Paul,
Yes that looks like it eliminates the need for !important on the 300% width of the UL since it is the container.

We’re still having to override some of the LI styles with !important though. The LI’s are the children and the script is setting them as position:absolute; along with calculated heights.

That removes the resizing that scripting does, but now introduces more CSS issues, such as needing to set the height of the slides ul element to be able to see the content
I think that was because the script was setting them as AP that I mentioned above. When I set position:relative !important; and height:auto!important; the UL height is no longer a problem.

So if we could stop it from applying styles to the LI (children) that would help too.

We could set a min-height on the UL to keep it from changing heights with the fluid content list-items, That allows it to expand it’s height at narrowed widths.

Here is what it requires now when using containerResize: false :


/* ----- Slideshow UL ------*/
#slideshow .slides ul {
    float:left;
    [COLOR=Blue]width:300%;
    min-height:240px;[/COLOR]
    /*background: #EEE;/*for testing widths*/
}
#slideshow .slides li {
    float:left;
    [COLOR=Blue]width:33.3% [COLOR=Red]!important[/COLOR];
    position:relative [COLOR=Red]!important[/COLOR];
    height:auto [COLOR=Red]!important[/COLOR];[/COLOR]
    background: #CDF;/*for testing widths*/
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <title>Fluid Width jQuery Slideshow</title>
    <script type="text/javascript" src="http://doubledee.byethost2.com/js/jquery.min.js"></script>
    <script type="text/javascript" src="http://doubledee.byethost2.com/js/jquery.cycle.all.min.js"></script>

<script type="text/javascript">
$slideshow = {
    context: false,
    tabs: false,
    timeout: 3000,      // time before next slide appears (in ms)
//    timeout: 1000,      // time before next slide appears (in ms)
    slideSpeed: 500,   // time it takes to slide in each slide (in ms)
//    slideSpeed: 1000,   // time it takes to slide in each slide (in ms)
    tabSpeed: 400,      // time it takes to slide in each slide (in ms) when clicking through tabs
    fx: 'scrollRight',   // the slide effect to use
//    fx: 'scrollLeft',   // the slide effect to use
//    fx: 'fade',   // the slide effect to use

    init: function() {
        // set the context to help speed up selectors/improve performance
        this.context = $('#slideshow');

        // set tabs to current hard coded navigation items
        this.tabs = $('ul.slides-nav li', this.context);

        // remove hard coded navigation items from DOM
        // because they aren't hooked up to jQuery cycle
        this.tabs.remove();

        // prepare slideshow and jQuery cycle tabs
        this.prepareSlideshow();
    },

    prepareSlideshow: function() {
        // initialise the jquery cycle plugin -
        // for information on the options set below go to:
        // http://malsup.com/jquery/cycle/options.html
        $("div.slides > ul", $slideshow.context).cycle({
            fx: $slideshow.fx,
            timeout: $slideshow.timeout,
            speed: $slideshow.slideSpeed,
            fastOnEvent: $slideshow.tabSpeed,
            pager: $("ul.slides-nav", $slideshow.context),
            pagerAnchorBuilder: $slideshow.prepareTabs,
            before: $slideshow.activateTab,
            pauseOnPagerHover: true,
            pause: true,
            [COLOR=Blue]containerResize: false[/COLOR]
        });
    },

    prepareTabs: function(i, slide) {
        // return markup from hardcoded tabs for use as jQuery cycle tabs
        // (attaches necessary jQuery cycle events to tabs)
        return $slideshow.tabs.eq(i);
    },

    activateTab: function(currentSlide, nextSlide) {
        // get the active tab
        var activeTab = $('a[href="#' + nextSlide.id + '"]', $slideshow.context);

        // if there is an active tab
        if(activeTab.length) {
            // remove active styling from all other tabs
            $slideshow.tabs.removeClass('on');

            // add active styling to active button
            activeTab.parent().addClass('on');
        }
    }
};


$(function() {
    // initialise the slideshow when the DOM is ready
    $slideshow.init();
});


$('#s1').cycle({timeout:2000});

$('#pauseButton').click(function() {
    $('#s1').cycle('pause');
});
</script>

<style type="text/css" >
body {
    margin: 0;
    padding: 0;
    font: 100%/1.3 arial, helvetica, sans-serif;
}
#slideshow {
    width: 70%;
    min-width: 400px;
    max-width: 800px;
    margin: 30px auto;
    background: #EEE;
    border: 1px solid #ddd;
}
#slideshow ul {
    margin: 0;
    padding: 0;
    list-style: none;
}
.slides {
    overflow: hidden;
}
/* ----- Slideshow UL ------*/
#slideshow .slides ul {
    [COLOR=Blue]float:left;
    width:300%;
    min-height:240px;[/COLOR]
    /*background: #EEE;/*for testing widths*/
}
#slideshow .slides li {
    [COLOR=Blue]float:left;
    width:33.3% !important;
    position:relative !important;[/COLOR]
    [COLOR=Blue]height:auto !important;[/COLOR]
    background: #CDF;/*for testing widths*/
}
#slideshow .slides li#slide-three {
    margin-right:-1px;/*soak up rounding errors*/
}

#slideshow .slides h2 {margin: 5px 10px 0;}
#slideshow .slides p {margin: 10px;}

/* ---- slideshow nav ----*/
#slideshow .slides-nav {
    clear: both;
    background: #DDD;
    border-top: 2px solid #ccc;
    overflow: hidden;/*contain floated li*/
}
#slideshow .slides-nav li {
    float: left;
}
#slideshow .slides-nav li a {
    float: left;
    padding: 15px 20px;
    outline: none;
}

</style>    
</head>
<body>

<div id="slideshow">
    <div class="slides">
        <ul>
            <li id="slide-one">
                <h2>Slide one</h2>
                <p>
                    Lorem ipsum dolor sit amet, consectetur adipiscing elit.
                    Donec pretium arcu non velit. Phasellus adipiscing auctor
                    lorem. Curabitur in urna ut purus consequat sollicitudin.
                    Phasellus ut diam.
                </p>
                <p>
                    Lorem ipsum dolor sit amet, consectetur adipiscing elit.
                    Donec pretium arcu non velit. Phasellus adipiscing auctor
                    lorem. Curabitur in urna ut purus consequat sollicitudin.
                    Phasellus ut diam.
                </p>
            </li>
            <li id="slide-two">
                <h2>Slide two</h2>
                <p>
                    Nam ac nibh sit amet augue ultricies sagittis. Donec sit
                    amet nunc. Vivamus lacinia, nisi ac tincidunt commodo, purus
                    nisi condimentum urna, sit amet molestie odio dolor non lectus.
                    Cum sociis natoque penatibus et magnis dis parturient montes,
                    nascetur ridiculus mus.
                </p>
            </li>
            <li id="slide-three">
                <h2>Slide three</h2>
                <p>
                    Lorem ipsum dolor sit amet, consectetur adipiscing elit.
                    Suspendisse adipiscing dui a nibh. Integer tristique lorem
                    vitae massa. Etiam dapibus, eros sit amet euismod semper,
                    felis erat congue lacus, sed aliquam metus libero sed elit.
                </p>
            </li>
        </ul>
    </div>
    <ul class="slides-nav">
        <li><a href="#slide-one">Slide one</a></li>
        <li><a href="#slide-two">Slide two</a></li>
        <li><a href="#slide-three">Slide three</a></li>
    </ul>
</div>

</body>
</html>

Hi Victor,

Yes, that is the goal, to get rid of the inline styles that the script is injecting. :wink:

Hi,

Using the example that Vic posted I managed to get something working with a bit of fiddling.

This looks pretty close to what you want.

It will work with any number of slides automatically without changing the css, The only manual thing to do is to add the altlinks by hand.


    <p id="nojs" class="altlinks"><a href="#slide1">Slide 1</a> | <a href="#slide2">Slide 2</a> | <a href="#slide3">Slide 3</a></p>

The above links are only visible when js is turned off and use the fragment identifier to rotate the content.

They suffer from the same problem as the existing one in that if JS is turned off and the page is resized while you have clicked one of the slides then as you open the page the scroll position is altered and a previous slide can be seen. Once you click the link again then it clicks back to normal.

I believe this would be a problem with any fragment identifier and overflow method used in a similar way and don’t see a solution (unless someone else can see a different way to do this). If the slide had a fixed height then we could get around this but that would ruin the fluid nature of the slide.

Hi Paul, yes that is much cleaner :slight_smile:

I had tried using white-space:nowrap along with inline-blocks too but I ran into to problems when using the previous script. Looking back now I think it was because I was not overriding the AP that the script was injecting.

The above links are only visible when js is turned off and use the fragment identifier to rotate the content.
That seems more appropriate too.

They suffer from the same problem as the existing one in that if JS is turned off and the page is resized while you have clicked one of the slides then as you open the page the scroll position is altered and a previous slide can be seen. Once you click the link again then it clicks back to normal.
Like you, I don’t see any way around that. That looks like the price that has to be paid for the side scrolling CSS only version.

I believe this would be a problem with any fragment identifier and overflow method used in a similar way and don’t see a solution (unless someone else can see a different way to do this). If the slide had a fixed height then we could get around this but that would ruin the fluid nature of the slide.
The only thing that might help would be a min-height on the LI for the CSS only version, untested though.

All in all, I think you’ve got the cleanest thing going so far :wink:

There’s not any other fluid width sliders running around out there that I know of so were treading in uncharted waters here.

EDIT:
BTW, I was playing around with TinySlider 2 earlier as an attempt to get away from the jQuery library.
It uses a very lean standalone javascript. It requires the onclick events in the html for the navigation though.

Paul, thanks for going the extra mile.

Not to seem ungrateful, but it introduces some new issues (unless I’m missing something)…

1.) The user has to “start” the slide-show. (Because this is for my home page, it should play automatically. The goal is to “force-feed” people content in case they don’t navigate on their own to what I want them to see!)

2.) When the slide-show is playing, the height of the slide-show varies. Now, obviously, the height will change if you adjust the browser width, but when that is constant, the slide-show box should be a set height.

If it isn’t, it cause two issues… First, it makes you dizzy with all of that changing. Second, it would readjust the entire home page. (There will be normal <p>'s after the slide-show and they shouldn’t be hoping around.

3.) Slides #2 and #3 go one direction and Slide #1 goes another direction. That looks really confusing. Maybe it’s any easy fix.

Thank you, AGAIN, for yet another way to tackle my original problem! If the above issues can be addressed, it may be a viable solution.

(I guess we don’t have anyone here that could point me to the right place in the original example’s JavaScript to tinker with that code, huh?)

They suffer from the same problem as the existing one in that if JS is turned off and the page is resized while you have clicked one of the slides then as you open the page the scroll position is altered and a previous slide can be seen. Once you click the link again then it clicks back to normal.

I believe this would be a problem with any fragment identifier and overflow method used in a similar way and don’t see a solution (unless someone else can see a different way to do this). If the slide had a fixed height then we could get around this but that would ruin the fluid nature of the slide.

I don’t see any issues when JavaScript is off. In FF on my Mac, everything adjusts properly and as you click through each tab manually, things look and behave as they should. (For me, it was when JavaScript was turned on that things looked like we took a step backwards…)

Thanks,

Debbie

1.) The user has to “start” the slide-show. (Because this is for my home page, it should play automatically. The goal is to “force-feed” people content in case they don’t navigate on their own to what I want them to see!)
Just set the autoPlay to true in the .ready(function of the script at the end of the html.

    <script type="text/javascript">        
                $(document).ready(function(){ $('#fluidslide').jshowoff({ 
                  effect: 'slideLeft',
                    cssClass: 'hidelinks',
                    hoverPause: false,
                    [B][COLOR=Black]autoPlay: true [/COLOR][/B]
                }); 
                $("#nojs").hide();
                });
            </script>

Likewise I would probably set the hoverPause: to “true” also. That allows them to pause it with their cursor and read the entire content before it slides away.

But that’s what would happen when you had a fluid page anyway. When you reduce the height of fluid content the page grows. I don’t see how you can have both at the same time. The only way in CSS we can accomodate the fluid height text is by not setting a height.

However, if Paul W or some other kind soul wants to code this in javascript then here’s what they’d have to do:

On browser resize cycle through the slides in the page and find the tallest one and then set the height of all slides to that tallest height. This would have to happen on browser resize and would ensure that each slide is the same height for the current width of the screen.

The drawback is that the onresize event usually slows the page down and makes opening and closing the window a little choppy.

Oops, I was changing the settings in the JavaScript file instead of the HTML file. Duh! :blush:

Likewise I would probably set the hoverPause: to “true” also. That allows them to pause it with their cursor and read the entire content before it slides away.

Agreed.

Okay, so that fixes one of my issues. :slight_smile:

Debbie

That is why I proposed setting a min-height on the LI. It’s not a cure all but it will stop it from jumping up and down when the page is at it’s max-width.

The content in these sliding elements should limited anyway since they are just brief intros. Pick the one with the most text and set a min-height according to it. :wink:

Hmm… Let me explain what I’d like.

If you go back to my original example here…

…you will see that the height remained the same between slides. That was important, because Slide #1 was three paragraphs high, whereas Slides #2 and #3 were only one paragraph high.

By making all slides the same height as the tallest slide, things looked uniform and you don’t get the “jumping” that we have now.

This is how things should work in my mind…

The slides should all be the same height and that height should accommodate the tallest slide (e.g. height: 10em) at the widest browser setting (i.e. full-screen). Then if the user reduces the browser size, obviously the middle column’s width would shrink - thus forcing the slide-show to be skinnier as well - and the slides would need to be taller (e.g. height: 20em)

I have no problem with the slides height increasing to accommodate a narrower middle column. All I am wanting is for all the slides to be the same height.

That seems like a fair and flexible compromise to me, right? :slight_smile:

Can’t that be done in the CSS?

Thanks,

Debbie

But better than a Min-Height, is a uniform height like my original example! :smiley: (Not sure how we did it, but I thought it looked great.)

The content in these sliding elements should limited anyway since they are just brief intros. Pick the one with the most text and set a min-height according to it. :wink:

I suppose that is doable.

Okay, but dumb question… If we set the Min-Height to 10em, and then I had a slide that needed 15 lines - which I think would be 15em - would that keep all of the slides equal height, or would you have all of the other slides at the Min-Height of 10em and the big slide at 15em?! :-/

Debbie

Yes, that would be a partial solution but seems to defeat the purpose of a fluid layout to me :).

I’ve added a min height in here for testing.

I also tried to make it only slide one way but it seems as though I broke something along the way as the original slide doesn’t slide out of the way now but just gets covered up.

However, I think the one direction slide is less accessible because the user doesn’t know when they have got to the end of the slides. Most of these scripts do a similar reverse slide once you’ve reached the end of the slides otherwise the user just keeps clicking on forever.

Your original example was not a fluid width slider, your min-max widths were not working correctly. Maybe it looked good but I don’t think you stress tested it.

Reduce your viewport width and you will see that overflow:hidden on the .slides along with the injected widths from the script was throwing everything off.

That what most of this thread was about, cleaning all that up. :slight_smile:

There is a PRICE to pay for this fluid width slider, you can’t have it both ways.

EDIT:
I think the best thing you could do is be a “word crafter”, by that I mean select a fairly equal amount of Key-Words for each section.

These are really just brief intros and if you can keep the content amount consistent then it will prevent jumping and they will all wrap to consistent heights with the fluid widths.

Paul,

I took Rayzur’s advice and added a Min-Height, which seems to work.

Also found a way to get the slides going the same way, although it doesn’t sound like you like that. (Will post my corrections for all to see in a bit!) :slight_smile:

BTW, two more less important issues…

1.) How does he get those “pretty” borders around the numbers and controls so they look like reversed buttons? (See slide show with Back Lab here… jShowOff: a jQuery Content Rotator Plugin by Erik Kallevig)

Oh, and is there is a simple way to do that that is supportable by all browsers (i.e. no CSS3) then that would help!)

2.) If I slow down my slide-show, can I insert Hyperlinks in a slide, so I user could click on it and go to a page with more information?

Thanks,

Debbie

No, I know it wasn’t working and that is why I’ve created another monster thread! :stuck_out_tongue:

I just meant I liked how the height was constant.

That what most of this thread was about, cleaning all that up. :slight_smile:

There is a PRICE to pay for this fluid width slider, you can’t have it both ways.

You, Paul and I seem to be racing to correct each other today! :lol:

See my last post. Took your advice and we are making progress. (I even took a stab at the JavaScript - which is a little easier to follow than that first plug-in - and made some minor improvements which I’ll post later.)

Go CSS Team!! :cheer:

Debbie

See my last post. Took your advice and we are making progress.
The min-height I suggested was not a cure-all, it was really only good for the page at it’s max-width.

See the edit to my last post, that is what I would be doing. :wink:

2.) If I slow down my slide-show, can I insert Hyperlinks in a slide, so I user could click on it and go to a page with more information?

You shouldn’t have to be concerned about that now with the hover pause set to true.

Yes, “word crafting” - as you say - makes sense.

I’m sure if I play around with things, I can find a combination of Content and Min-Height that work at both the Min and Max Widths.

You shouldn’t have to be concerned about that now with the hover pause set to true.

So, what I meant was, “Is there any reason with all of this JavaScript stuff that I cannot use Hyperlinks?” (Since we made my static HTML slides dynamic, I thought maybe that would cancel out the ability to use Hyperlinks?!)

One last thing, back to my other question…

Is the pretty rounded button-like look, from CSS3?

Is there anyway to do that in a more supported way?

The only ways I can think would be 1.) Wrap the text in DIVs and style them like they are buttons, or 2.) Maybe add background shading and padding to the Text itself to create the illusion of a square/rectangular buttons? :-/

Thanks,

Debbie