5
SHARES
How to make a 3 Panel Slider
March 17, 2014
3 comments
23,618
This tutorial will teach you how to create a slider divided into 3 rectangle portraits that moves independently from one another but together creates a complete picture. The perfect use of this slider is to highlight beautiful images like landscapes. I think this slider will work best with images whose elements are present all across the image like wide city photos, wide landscapes or beautiful wide architecture.

The slider features arrows controls for Next Side and Previous Slide and Bottom Navigation that displays the current slide and changes the slide when you click on a dot. You will be able to add a large number of images because the slider is designed to work with unlimited number of images. The slider has one copy of each image in every panel, all images will be summoned from "slider-panel-images"  into all 3 of the panels using jQuery's append function. Images will be changed once every 10s by setInterval function in JavaScript.

Image credit goes to Daniel Zedda on Flickr. Next Slide and Previous Slide icons where created using icomoon.  

This tutorial will only work on browsers that supports the most recent CSS3 features and this tutorial is not ready for production.

HTML

The html has a few main elements. The slider-panels is the one who holds up each of the three individual panels. The first panel is called id="slider-panel-left" and it holds id="slider-panel-left-carousel" which in terms holds class="slider-panel-left-carousel-tab" which holds a single image. Please note that id="slider-dots" or class="slider-panel-left-carousel-tab" or class="slider-panel-center-carousel-tab" or class="slider-panel-right-carousel-tab", as well as the image inside of it will not be present in the final demo, because it will be dynamically generated by the JavaScript in each panel based on the number of images we will add in id="slider-panel-images". This code block is designed to show how the final html will look once the JavaScript takes over.

CSS

This demo its not responsive, this is why each element has a fixed size. The first element that we will write rules for is the '#slider' div:



This element will hold both the '#slider-panels' div, which will hold all 3 panels, as well as '#slider-dots', which will display the current slide and controls.



'.slider-dot' will be replicated to create one class for each image using jquery, it also has a css3 transition added for the background when the mouse hovers to make a smoother transition. '.slider-dot-current' is the class that will be added to each div '.slider-dot' to display the current slide.
Inside '#slider-panels' we will see '#slider-panel-images', which will be the place where we will put all the images we want in the slider. Those images will need to be 900px in width and 400 in height. We will set '#slider-panel-images' to invisible because we won't use this to display our images, this is just a place to put them all together and load them later into the page.



Next in line are the arrows that controls the current slide '#slider-panels-next' and '#slider-panels-previous'



Both elements have transition set in order to make the background fade in smoother when you hover over them. We have finally got to the most important part of our slider, those 3 panels. The left panel is called ‘#slider-panel-left’, the center ‘#slider-panel-center’ and finally right panel ‘#slider-panel-right’.
Each panel has another div inside which will hold the images, for example the left slider has one ‘#slider-panel-left-carousel’ his position is set to absolute and we will use JavaScript to control his position inside ‘#slider-panel-left’. We are not done yet, in order to make sure our images will look good we will have to create another element ‘.slider-panel-left-carousel-tab’ inside ‘#slider-panel-left-carousel’ which we will replicate for each image. The reason I went for this approach is because we need to only show one part of the image and not all image. For example, if an image is 900px in width and 400px in height, '.slider-panel-left-carousel-tab’ will only display the left part of the image, the 300px by 400px part of the image to be more specific. The rest wil be hidden using overflow: hidden;



You will notice that I have set '#slider-panel-left-carousel' and '#slider-panel-right-carousel' width to 0px and '#slider-panel-center-carousel' height to 0px, the reason is that those values don't really matter, because they will be later set in jQuery to fit all the images.
The right and left panel will be moving horizontally - the left one will move from right to left and the right panel will move from left to right. The center panel will move vertically and not horizontally, that's why set the width and not the height, this panel will move from bottom to top.
You will ask yourself why I didn't made all the carousels to move from top to bottom or left to right and why I have used so many ID elements instead of creating 3 generic classes for all panels. The reason I chose to move the panels independently is to create a nicer transition, as for the ID vs Classes I made this decision in order to make it easier for you to identify which panel is which.

JavaScript

Let start out by setting some variables that will make youre life easier later when you want to change those numbers.



The ‘slideTiming’ variable will controls the time it takes before changing to the next slide, ‘animationTime’ is the animation duration between the slides, ‘controlsHideTime’ variable changes the time it takes for the next and previous buttons to hide, ‘current’ represents the current slide or the opening slide position.
Next we will take care of the arrows using jquery hover.



We will use check_slide() function to check the current position and animate the slider accordingly. The left panel will have it’s position animated to the right using animate function but using a negative values. The value is provided by multiplying the width of the slide with the ‘current’ variable that indicated the current slide minus 1 because we want to take into account the case where the ‘current’ will be on and the result will be 0 so the position won’t change. The same goes for the right tab but in opposite direction, with the center panel its a different story because i wanted the slide to move up and down not from side to side and we will change the top position to minus 400, the height of the panel with the ‘current’ minus 1.
The other thing that we have to do in this function is to first remove the class ‘.slider-dot-current’ from all ‘.slider-dot’ and then add ‘.slider-dot-current’ only to the appropriate position. You will see that we are using data-slide attribute in order to find the appropriate element that needs to be changed, i will talk later about this attribute.



We will now write the function that changes the slides both when you press the arrows or when the autochange function is activated this will also reset ‘current’ variable and summon check_slide(); function to change the slider.



Lets go ahead and add controls for the arrows also:



setInterval will take care of the automated slider switching:



In the next step we will be looping through the images located in ‘#slider-panel-images’ and append them in all of the 3 panels. We will also add the small dots at the bottom of the slider to display the current position of the slider. We are adding the attribute ‘data-slide’ to each ‘.slider-dot’ in order to identify and change the dots to display the current slide.
We will need to change the size of all 3 carousel that are filled with images. The side ones will need width adjustments and the center one will need height adjusted. We will also need to change the width ‘#slider-dots’ because it won’t stay centered if it doesn’t have a width.



The last thing we have to do is change the slide when someone is clicking on ‘.slider-dot’. We will do that by setting the variable ‘current’ equal to the number inside the attribute ‘data-slide’ and by calling the function check_slide()
We will have to call the check_slide() function one more time outside the click function because we also need to check the current slide when a page loads.

5
SHARES
0
2
3
0
About the author
Popa Robert: Is the founder of Simbyone.com, freelance web developer and designer, he likes to create beautiful websites and water cooled PC's
3 Comments
Responsive
May 18, 2015
This one is awesome. However, I can't use it in my new project, because it's not responsive. Are you planning any update?
Robert Popa
May 18, 2015
Thanks, Yes i am planning an update in a few months with responsive design with tables. Subscribe to newsletter if you don't want to miss the update.
Responsive
May 18, 2015
Sweet! I can't wait :) Few months is a long time, so I'm starting to search for similar slider now.
Would you like to share your thoughts?
Name:*
Email:*
Website:
Message:*
Fields marked with * are mandatory. We don't share your email with anyone. Email provided in the above fields are used for identification only. If you chose to subscribe to our newsletter you can cancel at any time.
Hot Posts
11,648
0 comments
1,238,227
23 comments
112,004
0 comments