Sometimes, We Write Stuff...
Mootools Content Slider Class
Due to the amount of redundant questions about old versions of the content slider, I've deleted the old versions from my site (such as this one) to eliminate further confusion.
Please visit the latest version, located here: Latest Content Slider Version.
Promote This Article
+ Comments
Just FYI, interferes with Ruby on Rails default scriptaculous library. Although works well without any built in rails functions.
Ahh, that's a bummer... sorry!
I'm not a big fan of Scriptaculous for many reasons, and now it looks like I have yet another item to add to that list. (And frankly, I'm very surprised that ROR would use such an inefficient JS library...)
I see that you have options for prev and next buttons, but not referenced in code - are you planning to update the changeIt function to allow prev/next?
I'm having a problem with this class in IE 7 when I attempt to place the sliding content div inside another div. For some reason, certain elements in the slide item divs do not always slide. For instance, I've got an h1, an h3 and a p within my sliders. Right now, the h3 and the p slide, but the h1 items for every slider are present and will not slide when I call slideIt. I figure this is a css issue, but other than font-size, there is no difference between my h1, h3, and p declarations in the css. In firefox, everything works just dandy. If I remove the sliding content from the parent div that I have created, the class works just fine in IE. I'd love to run it that way, but then I run into issues with the way I'm trying to present my content. Got any ideas?
I appear to have solved my non-moving element problem (IE 7) with the slider when it's inserted inside of another div. If I declare widths for each item class element (h1, h3, p, etc.), all the elements seem to move. CSS problem, after all!
Thank you very much for this really good script. but I tried to put some links inside and it failed... Is it impossible? Thanx
Here are some updates to make this class work with forward/back navigation, as well as being able to pass in the text for forward/back/pause/play on the fly. This will also work to use images as the nav.
Add these to your options:
playBtnText: null, //text/html tags to show up for 'play'
pauseBtnText: null, //text/html tags to show up for 'pause'
prevBtnText: null, //text/html tags to show up for 'previous'
nextBtnText: null //text/html tags to show up for 'next'
During initialization you need to add click event handlers for previous and next. This also sets the 'text' for the buttons (I'm using icons/graphics). Here's the new initialization:
initialize: function(options) {
//set options
this.setOptions(options);
//remove any scrollbar(s) on the container
this.options.container.setStyle('overflow', "hidden");
//if there is a play/pause button, set up functionality for it
if(this.options.hasControls != false) {
this.pauseIt.bind(this);
this.options.playBtn.setHTML(this.options.pauseBtnText);
this.options.prevBtn.setHTML(this.options.prevBtnText);
this.options.nextBtn.setHTML(this.options.nextBtnText);
this.options.prevBtn.addEvents({
'click': function() {
var move_to = this.options.itemNum-1;
if(move_to < 0) {
move_to = this.options.items.length-1;
}
this.pauseIt();
this.slideIt(move_to);
}.bind(this),
'mouseenter' : function() {
this.setStyle('cursor', 'pointer');
}
});
this.options.nextBtn.addEvents({
'click': function() {
this.pauseIt();
this.slideIt();
}.bind(this),
'mouseenter' : function() {
this.setStyle('cursor', 'pointer');
}
});
this.options.playBtn.addEvents({
'click': function() {
this.pauseIt();
}.bind(this),
'mouseenter' : function() {
this.setStyle('cursor', 'pointer');
}
});
this.options.playBtn.addEvent('mouseenter', function() {this.setStyle('cursor', 'pointer');} );
}
//setup items (a.k.a. slides) from list
this.options.items.each(function(el, i){
//f.y.i. el = the element, i = the index
//positioning/opacity setup
el.setStyle('position', "absolute");
//get size of item and move that far above the container
var itemH = el.getSize().y;
var itemW = el.getSize().x;
//el.setStyle('top', (-1 * itemH));
el.setStyle('left', (-1 * itemW));
// -- Number nav setup
if(this.options.numNavActive){
//create numbered navigation boxes, and insert into the 'num_nav' ul)
var numItem = new Element('li', {id: 'num'+i});
var numLink = new Element('a', {
'class': 'numbtn',
'html': (i+1)
});
numItem.adopt(numLink);
this.options.numNavHolder.adopt(numItem);
this.numNav.push(numLink);
numLink.set('morph', {duration: 100, transition: Fx.Transitions.linear, link: 'ignore'});
numLink.addEvents({
'click' : this.numPress.bindWithEvent(this, i),
'mouseenter' : function() {
this.setStyle('cursor', 'pointer');
}
});
//set initial number to active state
if(i == this.options.itemNum){
var initNum = this.numNav;
initNum.addClass('active');
}
}
//end if num nav 'active'
}, this);
},
pauseIt() now requires that you change the text/html on the button. This was originally hard coded, now it'll run off of the parameters we passed in:
pauseIt: function () {
//only move if not currently moving
if(this.isSliding == 0){
if(this.options.isPaused == 0){
this.options.isPaused = 1;
$clear(this.theTimer);
this.options.playBtn.setHTML(this.options.playBtnText);
}
else{
this.options.isPaused = 0;
this.slideIt();
this.theTimer = this.slideIt.periodical(this.options.slideTimer, this, null);
this.options.playBtn.setHTML(this.options.pauseBtnText);
}
} //end if not sliding
},
Hopefully this helped someone out there. Thanks again to Daniel for creating this script.
@Cory: can you post the whole thing?? (zipped) Donno why,, but it aint working going forward AND backwards..??
And, (forgot to write early), if i update the script, i dont get a navigation at all..
How do we set it to pause initially and only move when someone pushes next/page number? Also, is there a way to make it move left and right? Like move left if you push a prev button and right if you push next?
Cory, you rock!
Everyone else, hold tight... I've written an update for this thing, I just need to find a little time to post the write-up. Maybe this weekend - but definitely soon! ![]()
Ah, look at this, just what I was looking for to play with this weekend. Thanks Ya'all!
Here's a preview of your comment:
Perfect, i've been checking back for updates. this is awesome.