1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
| <script type="text/javascript">
(function($){
function SlideShow(base){
this.currentPosition = 0;
this.slideWidth = 560;
this.slides = $('.slide', base);
this.numberOfSlides = this.slides.length;
// attention jQuery peut modifier this
var self = this;
// j'ai réécrit ce passage pour le plaisir,
// mais sous cette forme il demande jQuery 1.4 !!
this.slides.wrapAll(
$("<div/>", {
class: "slideInner",
css: {
float:"left",
width:self.slideWidth
}
};
);
$('.slidesContainer',base).css('overflow', 'hidden');
$('.slideInner',base).css('width', self.slideWidth * self.numberOfSlides);
$(base)
.prepend('<span class="leftControl">Move left</span>')
.append('<span class="rightControl">Move right</span>');
$('.leftControl', base).bind('click', self.onLeftControlClick);
$('.rightControl', base).bind('click', self.onRightControlClick);
this.manageControls();
}
SlideShow.prototype.manageControls = function(){
if (this.currentPosition == 0){
$('.leftControl', this).hide();
}
else
{
$('.leftControl', this).show();
}
if (this.currentPosition == (this.numberOfSlides - 1)){
$('.rightControl', this).hide();
}
else
{
$('.rightControl', this).show();
}
}
SlideShow.prototype.animate = function(){
// attention jQuery peut modifier this
var self = this;
alert('Anime');
$('.slideInner', this).animate({ 'marginLeft' : self.slideWidth * (-self.currentPosition)});
}
SlideShow.prototype.onLeftControlClick = function(){
alert('Hit left');
this.currentPosition++;
this.manageControls();
this.animate();
}
SlideShow.prototype.onRightControlClick = function(){
alert('Hit Right');
this.currentPosition--;
this.manageControls();
this.animate();
}
$.fn.SlideShowManager = function() {
return this.each(function(){
$.extend(this, new SlideShow(this));
});
};
})(jQuery);
$(function(){
$(".slideshow").SlideShowManager();
});
</script> |
Partager