/*--Main Container--*/
.main_view {
position: relative;
}
/*--Window/Masking Styles--*/
.window {
width: 455px;
height:351px;
overflow: hidden; /*--Hides anything outside of the set width/height--*/
position: relative;
float: left;
}
.image_reel {
position: absolute;
top: 0; left: 0;
}
.image_reel img {float: left; border:none; z-index:100;}
/*--Paging Styles--*/
.paging {
z-index: 1000; /*--Assures the paging stays on the top layer--*/
text-align: right;
display: none; /*--Hidden by default, will be later shown with jQuery--*/
padding: 0 15px 15px 0;
height: 15px;
background: #000000;
opacity: 0.7;
width: 440px;
margin-top: 282px;
}
.paging a {
font-weight: normal;
text-decoration: none;
color: #981e32;
height: 5px;
width: 10px;
outline:none;
padding: 3px;
font-family: Verdana, Geneva, sans-serif;
font-size: 20px;
}
.paging a:hover{
color: #ffffff;
}
.paging a.active {
font-weight: normal;
color: #ffffff;
}
.paging a:hover {font-weight: normal;}
JavaScript
$(document).ready(function() {
//Set Default State of each portfolio piece
$(".paging").show();
$(".paging a:first").addClass("active");
//Get size of images, how many there are, then determin the size of the image reel.
var imageWidth = $(".window").width();
var imageSum = $(".image_reel img").size();
var imageReelWidth = imageWidth * imageSum;
//Adjust the image reel to its new size
$(".image_reel").css({'width' : imageReelWidth});
//Paging + Slider Function
rotate = function(){
var triggerID = $active.attr("rel") - 1; //Get number of times to slide
var image_reelPosition = triggerID * imageWidth; //Determines the distance the image reel needs to slide
$(".paging a").removeClass('active'); //Remove all active class
$active.addClass('active'); //Add active class (the $active is declared in the rotateSwitch function)
//Slider Animation
$(".image_reel").animate({
left: -image_reelPosition
}, 500 );
};
//Rotation + Timing Event
rotateSwitch = function(){
play = setInterval(function(){ //Set timer - this will repeat itself every 3 seconds
$active = $('.paging a.active').next();
if ( $active.length === 0) { //If paging reaches the end...
$active = $('.paging a:first'); //go back to first
}
rotate(); //Trigger the paging and slider function
}, 5000); //Timer speed in milliseconds (3 seconds)
};
rotateSwitch(); //Run function on launch
//On Hover
$(".image_reel a").hover(function() {
clearInterval(play); //Stop the rotation
}, function() {
rotateSwitch(); //Resume rotation
});
//On Click
$(".paging a").click(function() {
$active = $(this); //Activate the clicked paging
//Reset Timer
clearInterval(play); //Stop the...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.