Reputation: 663
But with 4 images :
I can not find how to do What options should I use with fredcarousel can you refer me ?
Thanks
Upvotes: 1
Views: 1159
Reputation: 280
Here's a breakdown of what's going on in this carouFredsel example:
The author specifies the position of each element in the slideshow using variables:
var _center = {
width: 600,
height: 400,
marginLeft: 0,
marginTop: 0,
marginRight: 0
};
var _left = {
width: 300,
height: 200,
marginLeft: 0,
marginTop: 150,
marginRight: -150
};
var _right = {
width: 300,
height: 200,
marginLeft: -150,
marginTop: 150,
marginRight: 0
};
var _outLeft = {
width: 150,
height: 100,
marginLeft: 150,
marginTop: 200,
marginRight: -200
};
var _outRight = {
width: 150,
height: 100,
marginLeft: -200,
marginTop: 200,
marginRight: 50
};
And then uses the carouFredSel initiator to customize the scroll behavior:
$('#carousel').carouFredSel({
width: 900,
height: 400,
align: false,
items: {
visible: 3,
width: 100
},
scroll: {
items: 1,
duration: 400,
onBefore: function( data ) {
data.items.old.eq( 0 ).animate(_outLeft);
data.items.visible.eq( 0 ).animate(_left);
data.items.visible.eq( 1 ).animate(_center);
data.items.visible.eq( 2 ).animate(_right).css({ zIndex: 1 });
data.items.visible.eq( 2 ).next().css(_outRight).css({ zIndex: 0 });
setTimeout(function() {
data.items.old.eq( 0 ).css({ zIndex: 1 });
data.items.visible.eq( 0 ).css({ zIndex: 2 });
data.items.visible.eq( 1 ).css({ zIndex: 3 });
data.items.visible.eq( 2 ).css({ zIndex: 2 });
}, 200);
}
}
});
The onBefore event receives a number of different parameters containing current information about the slideshow. In this case, the first parameter is oldItems
, and then using the previously set "positions" (var _center
, var _left
, etc), the script animates the items to correspond.
These lines then set the css & z-index of the elements in the slideshow, after animation. It allows the slideshow to select the elements based on their css properties in a more efficient manner.
$('#carousel').children().eq( 0 ).css(_left).css({ zIndex: 2 });
$('#carousel').children().eq( 1 ).css(_center).css({ zIndex: 3 });
$('#carousel').children().eq( 2 ).css(_right).css({ zIndex: 2 });
$('#carousel').children().eq( 3 ).css(_outRight).css({ zIndex: 1 });
To adapt this to 4 elements, you'll need to add a 5th variable with positioning and a name like _farRight
and plug that into the script at each step.
Upvotes: 3