Image Slider with "Responsive Width", "Fixed Height", "Center Aligned" and "Auto Rotate"

user1830235 picture user1830235 · Mar 26, 2013 · Viewed 16.6k times · Source

I need a full width (responsive) slider with fixed height and centered image ( the min width is 960px and people with a wider screens will see the rest of the image (the extra on the left and right)) and it needs to auto-rotate.

Now I got the html/css worked out, but my javascript is rubbish so i have no idea how to let the images slide. I've checked out a lot of Questions here but nothing seems to work. My image dimensions are 2300x350.

CSS:

body {
    margin: 0 auto;
}

#slider_container {
    width:100%;
    height:350px;
    overflow:hidden;
    position: relative;
    z-index: 1;
}

.image {
    position:relative;
    float:left;
    height: 350px;
    width: 100%;
    overflow: hidden;
}

.image img {   
    position:absolute;
    left:50%;
    top:50%;
    margin-left:-1150px;
    margin-top:-175px;
}

HTML:

<div id="slider_container">
    <div class="image">
        <img src="images/header.jpg" />
    </div>
    <div class="image">
        <img src="images/header2.jpg"/>
    </div>
    <div class="image">
        <img src="images/header3.jpg" />
    </div>
</div>

With this code the pictures come out nice in the middle on every screen but how do I let it slide and autorotate? I guess the first image just needs to be replaced by the second so a z-index change? or + or - the width of one picture?

Answer

Jehanzeb.Malik picture Jehanzeb.Malik · Mar 26, 2013

You need to only style the img tag if using flexslider. Try the fiddle link below. I have included four files for this.

  • jQuery 1.9.1
  • flexslider.css
  • jquery.flexslider-min.js
  • bg_direction_nav.png

jsfiddle