Sometimes, We Write Stuff...

Mootools Content Slider Class

14 comments

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

  • StumbleUpon It
  • del.icio.us

+ Comments

#1
Swick said:
Oct 14, 2008 09:49

Perfect, i've been checking back for updates. this is awesome.

#2
Swick said:
Oct 14, 2008 02:23

Just FYI, interferes with Ruby on Rails default scriptaculous library. Although works well without any built in rails functions.

#3
Daniel said:
Oct 14, 2008 02:34

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...)

#4
Oct 21, 2008 05:11

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?

#5
James said:
Dec 02, 2008 09:04

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?

#6
James said:
Dec 03, 2008 03:34

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!

#7
koponic said:
Jan 26, 2009 04:03

Thank you very much for this really good script. but I tried to put some links inside and it failed... Is it impossible? Thanx

#8
Cory said:
Feb 27, 2009 10:20

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&#95;to < 0) {
                    move&#95;to = this.options.items.length-1;
                }
                this.pauseIt();
                this.slideIt(move&#95;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&#95;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.

#9
Blw said:
Mar 16, 2009 07:25

@Cory: can you post the whole thing?? (zipped) Donno why,, but it aint working going forward AND backwards..??

Blw said:
Mar 16, 2009 07:36

And, (forgot to write early), if i update the script, i dont get a navigation at all..

Pixiem said:
Mar 29, 2009 04:42

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?

Daniel said:
Apr 03, 2009 12:46

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! smile

Pixiem said:
Apr 28, 2009 09:11

"Patiently" awaiting your update... smile

May 15, 2009 10:16

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:

Commenting is not available in this section entry.