Ik heb een class geschreven voor mootools 1.2 die toegepast kan worden als slideshow.
Een voorbeeldje
Willen jullie eens testen of het allemaal werkt zoals de bedoeling is en eventuele suggesties/foutmeldingen + browser melden?
Bedankt!
Edit, de Class
/*
Class: cvSlideShow
Author: Crispijn Verkade
Website: http://crispijnverkade.nl
Version: 1.0 beta
Date: 10/03/2009
Built For: MooTools 1.2.0
*/
var cvSlideShow = new Class({
//implements
Implements: [Options],
//options
options: {
images: '.image',
buttons: '.nav_button',
autoplay: true, //bool
nextbutton: 'nav_next',
prevbutton: 'nav_prev',
pauzebutton: 'nav_play',
statbut: 'stat',
showtime: 2000, //milliseconds
duration: 500 //milliseconds
},
//initialization
initialize: function(options) {
//set options
this.setOptions(options);
this.images = $$(this.options.images);
this.currentImage = 0;
this.prepareEvents();
$(this.images[0]).get('tween', {property: 'opacity', duration: this.options.duration}).start([0,1]);
this.setStat();
if(this.options.autoplay == true){
this.startPauze();
}
this.navImages(this.options.autoplay);
},
prepareEvents: function(){
$(this.options.nextbutton).addEvent('click', this.toNextPrev.bind(this,'next',false));
$(this.options.prevbutton).addEvent('click', this.toNextPrev.bind(this,'prev',false));
$(this.options.pauzebutton).addEvent('click', this.startPauze.bind(this,[true]));
},
setStat: function(){
$(this.options.statbut).empty().set('html', 'Image' + (this.currentImage + 1).toInt() + '/' + this.images.length);
},
autoPlayStart: function(){
this.autoplay = this.toNextPrev.periodical(this.options.showtime,this,['next',true]);
},
autoPlayEnd: function(){
$clear(this.autoplay)
},
startPauze: function(){
if(this.run == true){
//pauze
this.autoPlayEnd();
this.run = false;
$(this.options.pauzebutton).empty();
new Element('img',{'src': 'images/nav_play.png'}).inject($(this.options.pauzebutton));
this.navImages(false);
}else{
//play
this.autoPlayStart();
this.run = true;
$(this.options.pauzebutton).empty();
new Element('img',{'src': 'images/nav_pauze.png'}).inject($(this.options.pauzebutton));
}
},
navImages: function(loop){
if(loop != true){
//button management
if(this.currentImage == 0){
//hide prev button
$(this.options.prevbutton).addClass('non_active');
}else if(this.currentImage == this.images.length - 1){
//hide next button
$(this.options.nextbutton).addClass('non_active');
}else{
$(this.options.nextbutton).removeClass('non_active');
$(this.options.prevbutton).removeClass('non_active');
}
}else{
$(this.options.nextbutton).removeClass('non_active');
$(this.options.prevbutton).removeClass('non_active');
}
},
toNextPrev: function(direction,loop){
$(this.images[this.currentImage]).get('tween', {property: 'opacity', duration: this.options.duration}).start([1,0]);
if(loop == true){
//loop the images array
if(direction == 'next'){
if((this.currentImage + 1) < this.images.length){
this.currentImage = this.currentImage + 1;
}else{
this.currentImage = 0;
}
}else if(direction == 'prev'){
if(this.currentImage === 0){
this.currentImage = this.images.length-1;
}else{
this.currentImage = this.currentImage - 1;
}
}
}else{
if(direction == 'next' && (this.currentImage + 1) < this.images.length){
this.currentImage = this.currentImage + 1;
}else if(direction == 'prev' && this.currentImage > 0){
this.currentImage = this.currentImage - 1;
}
}
$(this.images[this.currentImage]).get('tween', {property: 'opacity', duration: this.options.duration}).start([0,1]);
this.navImages(loop);
this.setStat();
}
});