Sudo Slider

  • Howto setup Sudo Slider

    If you are 100% lost, copy the basic example, and make sure that the links to the JavaScript and the css works, because i here assume that you already have a working setup of Sudo Slider.

    You start the slider by running a script that looks like this:

    <script>
    $(document).ready(function(){	
        var sudoSlider = $("#slider").sudoSlider({
            option1: setting1,
            option2: setting2,
            option3: setting3,
            option4: setting4
        });
    </script>

    Here a ready to use example:

    <script>
    $(document).ready(function(){	
        var sudoSlider = $("#slider").sudoSlider({
            continuous:        true,
            history:           true,
            numericText:       ['one','two','three'],
            customLink:        'a.tablink',
            updateBefore:      true,
            nextHtml:          '<span> next </span>'
        });
    </script>

    Remember to exclude the "," after the last setting.
    You can off course replace the "#slider" with any CSS selector.
    Here's a list of all options and an explanation of what they do.

    Methods

    Methods is what you use, if you want the slider to do somethings after Init.

    You do that by doing something like this:

    <script>
    $(document).ready(function(){	
        sudoSlider.goToSlide(1);
    });
    </script>

    This offcource requires that you saved the slider in the variable called "sudoSlider".
    The variable can have any name, you just need to make sure that you actually save the slider in a variable.

    Any of these methods can be used. (see examples of them below.)

    • .getOption(option); Returns the value of that option.
    • .setOption(option, value); Sets the value of an option.
    • .insertSlide(html, pos, [numtext]); Inserts a slide with the specified content into the slider. With the pos value you can set wich slide the content should be inserted after (and if pos == 0, the content is inserted before the other slides). And with numtext (it's optional), you can set the associated numericText.
    • .removeSlide(pos);Removes a slide.
    • .goToSlide(a, [speed]); Animate to slide [a] (1 is the first, and 'next', 'prev', 'first' and 'last' also works). If "speed" is set, the animations will take "speed" (where "speed" is a number) milliseconds to complete.
    • .block(); Blocks any user input.
    • .unblock(); Removes the above mentioned block.
    • .startAuto(); Starts an automatic slideshow.
    • .stopAuto(); Stop the automatic slideshow.
    • .destroy(); Destroys the slider, you can create it again by using .init();
    • .init(); Use this to initiate the slider, after it has been destroyed.
    • .getValue(name); This returns values like the current slide. Accepted value names: 'currentSlide', 'totalSlides', 'clickable', 'autoAnimation' and 'destroyed'.




    Below are example usage the different methods.

    <script>
    $(document).ready(function(){	
        // Returns the value of the option "fade".
       var fade = sudoSlider.getOption('fade');
       
        // Set the option "fade" to true. 
       sudoSlider.setOption('fade', true);
       
        // The content is inserted after the second slide. 
       sudoSlider.insertSlide('<p>This is some content</p>', 2, 'Content 3');
       
        // The second slide is removed.
       sudoSlider.removeSlide(2);
       
       // The slider animates to slide number 3.
       sudoSlider.goToSlide(3); 
       
       // User input is blocked (the controls)
       sudoSlider.block(); 
       
        // User input is unblocked.
       sudoSlider.unblock();
       
       // Starts a slideshow.
       sudoSlider.startAuto();
    
       // Stops an automatic slideshow.
       sudoSlider.stopAuto();
          
       // The slider is destroyed.
       sudoSlider.destroy(); 
       
       // Build it again.
       sudoSlider.init(); 
       
       // Returns the current slide number (starts from 1). 
       var currentSlide = sudoSlider.getValue('currentSlide'); 
       
       // Returns the total number of slides. 
       var totalSlides = sudoSlider.getValue('totalSlides'); 
       
       // Returns if the slider is currently clickable (true/false).
       var clickable = sudoSlider.getValue('clickable'); 
       
       // Returns if the slider is currently destroyed (true/false).  
       var destroyed = sudoSlider.getValue('destroyed'); 
       
       // Returns if the slider is currently running an automatic slideshow (true / false).
       var destroyed = sudoSlider.getValue('autoAnimation'); 
    </script>

    If you have any question, bug repport or spelling correction (English isn't my first language, so please correct me).
    Then plz leave a comment.

  • All options and what they do

    [option name]:[option default value]

    [description of the option]
    [Link(s) to example usage]


    Controls
    Slider behavior
    Ajax
    Full example

    Controls

    controlsShow:true

    If set to false, the controls (the numeric controls, and the prev, next, last and first buttons) will not be shown.

    controlsFade: true

    If set to false, the next/previous/first/last buttons won't fade away, when reaching the end of the slider, and continous == false.

    controlsFadeSpeed: '400'

    The speed of the fade animation of the previous and next buttons, when reaching the end of the slider and
    continuous == false and controlsFade == true.
    You can also use the values 'fast', 'normal' or 'slow'. (Which means 200, 400 and 600 milliseconds.)

    controlsAttr:'id="controls"'

    The attributes used in the "span" tag, that encloses all the generated controls.
    See designers guide for an explanation of exactly where this is placed.

    prevNext:true

    If false, the previous and next buttons will not be shown.
    It's still possible to make a next and previous buttons with customLink.
    demo of prevNext:false

    prevHtml:'<a href="#" class="prevBtn"> previous </a>'

    The HTML used for the previous button.
    It can be anything, as long as it's valid HTML with minimum 1 tag enclosing the whole thing.
    See designers guide for an explanation of where this HTML is positioned relative to the slider.

    nextHtml:'<a href="#" class="nextBtn"> next </a>'

    The HTML used for the next button.
    It can be anything, as long as it's valid HTML with minimum 1 tag enclosing the whole thing.
    See designers guide for an explanation of where this HTML is positioned relative to the slider.

    firstShow: false

    If set to true, the first button ('links' to the first slide) will be shown. (Default is that it's not shown. )

    firstHtml:'<a href="#" class="firstBtn"> first </a>'

    The HTML used for the 'first' button.
    It can be anything, as long as it's valid HTML with minimum 1 tag enclosing the whole thing.
    See designers guide for an explanation of where this HTML is positioned relative to the slider.

    lastShow: false

    If set to true, the last button ('links' to the last slide) will be shown. (Default is that it's not shown. )

    lastHtml:'<a href="#" class="lastBtn"> last </a>'

    The HTML used for the 'first' button.
    It can be anything, as long as it's valid HTML with minimum 1 tag enclosing the whole thing.
    See designers guide for an explanation of where this HTML is positioned relative to the slider.

    numeric:false

    If set to true, the numeric buttons will be shown.
    The text in these buttons can be specified with numericText.
    If set to 'pages', it will only make one button pr. [x] number of slides. (Where [x] is determined by the option "slideCount").
    numeric:true
    numeric:'pages'

    numericAttr:'class="controls"'

    The attributes used in the "ol" tag, that encloses all the generated numeric buttons.
    See designers guide for an explanation of exactly where this is placed.

    numericText:['1']

    The text used in the numeric buttons. This text is also used to specify the hash-url for each slide, which the history function use.
    Example usage is numericText:['First button text', 'Button number 2','This text comes in button number 3']
    Any length of text's can be used, since the default values (1,2,3,4,5,6......) will be inserted if nothing is specified.
    If using history, all values used must be unique like ['text1','text2','test3']. (If nothing is specified, it will still just use 1,2,3,4... as default values.)
    demo ussage of numericText

    customLink:false

    If set to a value (jQuery selector), all the matched objects can make a animation.
    Example usage of this variable is: customLink: 'div#customLinkbox a'.
    To specify what animation the slider is supposed to do, set a value in the "rel" attribute of the custromlink element. This can be a number (1,2,3..) or "next", "prev", "last", "first".
    You can place the customLinks wherever you want, even inside ajax-loaded or JavaScript generated content. If the selector is matched, it will work.
    Example usage in demo

    insertAfter: true

    If set to false, the auto generated controls will be inserted before the slider (before the <div id="#someID">...</div> ) instead of after.

    currentFunc:false

    A function that is run when an element (a customLink or a numeric control) gains the "current" class, which it does when the link represents the current slide.
    The t variable is the current slide number (starting from number 1).
    It's run once pr. item.
    Example usage:
    currentFunc: function(t){ $(this).children().fadeTo(500, 0.3);}
    demo usage of currentFunc
    Real world example

    uncurrentFunc:false

    Basically the same as currentFunc, but it's run when an element loses the "current" class.
    But the t variable is the slide number of the slide it was on. (Still starting form 1).
    It's still run once pr. element.
    demo usage of uncurrentFunc
    Real world example

    slideCount:1

    If you are showing more than 1 slide at the time, use this option to tell the slider how many slides you are showing.
    That way, the slider will adjust when to fade out controls, and also make some adjustments to continuous to make that work.
    demo usage of slideCount
    demo usage of slideCount & continuous

    moveCount:1

    This option adjust how many slides the slider moves when doing an animation to the "next" or the "previous" slide.
    demo usage of moveCount

    Slider behavior

    vertical:false

    If set to true, the slider will position the slides in a vertical line instead of in a horizontal line.
    You can allways manually position the slides just the way you want. This setting only affects some css properties of the <ul> container.
    demo of vertical:true

    speed:'800'

    This number value specifies the speed of the sliding animation in milliseconds.
    You can also use the values 'fast', 'normal' or 'slow'. (This means 400, 800 and 1200 milliseconds.)

    ease:'swing'

    Set the easing the document should make the animation with. This affects all sliding animations.
    There are 2 easings included in jQuery, and they are 'swing' and 'linear'
    Like any other jQuery plugin, you can also use non default easings, if you include a external JavaScript. Like the jQuery Easing Plugin.

    auto:false

    If set to true, the slider will automatically slide to the next slide after a specified period of time (see pause).
    This does not work with history, and it's not supposed to.
    The automatic sliding stops when a user makes the slider do something.
    demo of auto:true

    pause: '2000'

    Sets the duration of the pause (from one animation stops, till the next begin) in milliseconds, when auto is true.

    resumePause:false

    Pr. default the slider stops completely when a user makes the slider do something.
    But by using this variable, you can make the slider continue after X miliseconds of inactivity.
    demo of resumePause

    continuous:false

    If set to true, the slider will be continuous. Meaning that when sliding to the left of the first slide, you get the last (and if you slide the right of the last, you get the first).
    You could also say that the slider goes in a loop, if you continuously slide in one direction.
    If you use continuous, the slider creates clones of the outer content. This can cause some problems if you have flash content inside the slides.
    demo of continuous:true

    clickableAni:false

    If set to true, it is possible to click a control during a animation, and start a new animation immediately (the 'old' will stop).
    This only affects sliding animation, not fading animations.
    It's not a good idea to use this with history, since it can create some flickering (just don't do it, it looks weird).
    It's also not a good idea to use with "continuous:true", since it can cause the slider to act strange in some extreme situations.

    updateBefore: false

    If set to true, the numeric buttons (and the customLinks) will be given the class current when an animation is started, instead of when it finishes.
    demo of updateBefore:true

    history:false

    If set to true, the slider will track which slide you are at, by the URL. Meaning that bookmarks and the browsers back/forward buttons are supported.
    History works fully with fading animations, but if the user quickly changes 2 history "events" back, it can cause a image being changed instantly, instead of a fading animation.
    When using history, remember to include one of the required dependencies (see the demo), in order for it to work in old browsers.
    history:true in demo
    Real world example usage

    speedhistory:'400'

    Specifies the animation speed in milliseconds of the animation, when the animation is caused by a user not clicking a button in the slider, but by clicking the browsers back or forward button.
    You can also use the values 'fast', 'normal' or 'slow'. (This means 200, 400 and 600 milliseconds.)

    autoheight:true

    If set to true, it will automatically adjust the height of the slider, according to the height of the content within the current slide.
    If using Ajax, autoheight will launch after all the content in that slide (including all images) has been loaded.
    demo of autoheight:true

    autowidth:true

    If set to true, it will automatically adjust the height of the width, according to the width of the current slide.
    If using Ajax, autowidth will launch after all the content in that slide (including all images) has been loaded.
    demo of autoheight:true

    fade: false

    If set to true, the animations will be a fading animation instead of a sliding animation.
    Standard setting is a crossfading animation.
    demo of fade:true

    fadespeed:'1000'

    The length of the entire fade animation in milliseconds.
    You can also use the values 'fast', 'normal' or 'slow'. (Which means 200, 400 and 600 milliseconds.)

    crossFade:true

    If set to false, the fading animation will fade the whole slider (not the controls) out, and then fade it in. This looks best under some circumstances.
    Examples: crossfade:true, crossfade:false

    beforeAniFunc:false

    This function runs before the animation (any animation) starts.
    Example usage: beforeAniFunc: function(t){ alert($(this).html()); }
    The t variable is the number the slide have (the one the slider is animation towards). (As an example, the value of t is 2, when it's the second slide)
    And the variable 'this' is the slide it is animation towards.
    If you are ajax-loading some content, the function wont run untill all the content on the target slide has loaded.
    Note that SudoSlider creates clones of slides, to handle animations if you use either "continuous" or "fade" (with crossfade enabled). beforeAniFunc does also run the same script on these clones, so the script executes beforeAniFunc up to a theoreticly 4 times on different copies of the same slide.
    If you can't make things like "$(this).fadeOut(400);" work, try "$(this).children().fadeOut(400);"
    Example usage in demos

    afterAniFunc:false

    Same as beforeAniFunc. It's just runs after the animation (still any animation) has finished.
    beforeAniFunc does not execute multiple times if you use fade, but can still execute multiple times if you use continuous.
    Example usage in demos

    Ajax

    ajax:false

    With this variable, you can set which ajax documents are loaded into the slides.
    Example usage is: ajax: ['images/01.jpg', 'somedocument.html', 'images/anotherpic.png', false, 'lastdocument.html']
    In that example, slide 1,2,3 and 5 is are ajax-enabled, and the ajax content is loaded into the slides, but slide number 4 isn't touched.
    If it's not an image, the document will be loaded into the slide using the jQuery .ajax function.
    The default behavior of the JavaScript is to load the current slide and the next + previous slide.
    When using normal slide animations, the script will load all elements between the current slide, and the slider being animated to.
    Example usage in demo

    preloadAjax:100

    The default behaviour is that te script wait 100ms, after the last ajax-loading, then it preloads the next not-loaded slide.
    You can also set it to true, then the script will try to preload every slide from the beginning.

    loadingText:'Loading Content...'

    Sets the text that's shown before the ajax-content has been loaded.
    Example usage is: loadingText:'This document has yet to be loaded'

    startSlide:false

    Define the first slide to be shown. Example usage is startSlide:'2', which makes the slider show the second slide on load (the first slide is number '1', and not '0').
    Example usage in demos

    ajaxLoadFunction:false

    Using this variable, you can set a function to be run after somethings has been loaded into a slide. Any JavaScript can be used.
    The "this" variable is html of the slide, containing the image.
    Note that the function only runs, when ALL the content within the slide has loaded.
    Example usage:
    ajaxLoadFunction: function(t, img){ alert($(this).html()); }
    The "t" variable is the number the slide have. (As an example, the value of t is 2, when it's the second slide)
    the "img" variable is if the content was loaded as an image or as a document. (If true, content was considered an image).
    And the variable 'this' is the slide. Therefore, if you want to get the src of an image, this won't work "$(this).attr('src');" but this will $(this).children('img').attr('src');

    Full example

    With all options set to their default values.

    $(document).ready(function(){    
        $("#slider").sudoSlider({ 
            prevNext:          true,
            prevHtml:          '<a href="#" class="prevBtn"> previous </a>',
            nextHtml:          '<a href="#" class="nextBtn"> next </a>',
            controlsShow:      true,
            controlsAttr:      'id="controls"',
            controlsFadeSpeed: '400',
            controlsFade:      true,
            insertAfter:       true,
            firstShow:         false,
            firstHtml:         '<a href="#" class="firstBtn"> first </a>',
            lastShow:          false,
            lastHtml:          '<a href="#" class="lastBtn"> last </a>',
            numericAttr:       'class="controls"',
            numericText:       ['1'],
            vertical:          false,
            speed:             '800',
            ease:              'swing',
            auto:              false,
            pause:             '2000',
            continuous:        false,
            clickableAni:      false,
            numeric:           false,
            updateBefore:      false,
            history:           false,
            speedhistory:      '400',
            autoheight:        true,
            autowidth:         true,
            customLink:        false,
            fade:              false,
            crossFade:         true,
            fadespeed:         '1000',
            ajax:              false,
            loadingText:       false,
            preloadAjax:       false,
            startSlide:        false,
            ajaxLoadFunction:  false,
            beforeAniFunc:     false,
            afterAniFunc:      false,
            uncurrentFunc:     false,
            currentFunc:       false,
            slideCount:        1,
            moveCount:         1
        });
    });
  • Designers guide to Sudo Slider

    Controls

    When using Sudo Slider, there's only one requirement to the HTML: That the slider is a div, with a unordered list inside.
    Like this:

    <div id="slider">
        <ul>
            <li>Content</li>
            <li>Content</li>
            <li>Content</li>
            <li>Content</li>
            <li>Content</li>
        </ul>
    </div>

    When Sudo Slider loads, it makes some buttons, which easily can be targeted with CSS.
    This is the resulting HTML using the default configuration.

    <div id="slider">
        <ul>
            <li>Content</li>
            <li>Content</li>
            <li>Content</li>
            <li>Content</li>
            <li>Content</li>
        </ul>
    </div>
    <span id="controlsid">
        <a href="#" class="nextBtn"> next </a>
        <a href="#" class="prevBtn"> previous </a>
    </span>
    

    The Controls are positioned outside of the HTML, so that they won't conflict with the slider itself.

    And with every possible control enabled (still using the default configuration) the html ends up like this:

    <div id="slider">
        <ul>
            <li>Content</li>
            <li>Content</li>
            <li>Content</li>
            <li>Content</li>
            <li>Content</li>
        </ul>
    </div>
    <span id="controlsid">
        <a href="#" class="nextBtn"> next </a>
        <a href="#" class="prevBtn"> previous </a>
        <a href="#" class="lastBtn"> last </a>
        <a href="#" class="firstBtn"> first </a>
        <ol class="controls">
            <li rel="1" id="class="controls" class="current"><a href="#"><span>1</span></a></li>
            <li rel="2" id="class="controls"><a href="#"><span>2</span></a></li>
            <li rel="3" id="class="controls"><a href="#"><span>3</span></a></li>
            <li rel="4" id="class="controls"><a href="#"><span>4</span></a></li>
            <li rel="5" id="class="controls"><a href="#"><span>5</span></a></li>
        </ol>
    </span>

    If you then read the document descriping the different settings, you will see that much of this can be changed.
    Including inserting the controls before instead of after the slider using the option insertAfter
    In the next example, the option names for the various pieces of changeable HTML is shown instead of their default value.
    They are show like this: [optionname]

    <div id="slider">
        <ul>
            <li>Content</li>
            <li>Content</li>
            <li>Content</li>
            <li>Content</li>
            <li>Content</li>
        </ul>
    </div>
    <span [controlsAttr]>
        [nextHtml]
        [prevHtml]
        [lastHtml]
        [firstHtml]
        <ol [numericAttr]>
            <li rel="1" class="current"><a href="#"><span>1</span></a></li>
            <li rel="2"><a href="#"><span>2</span></a></li>
            <li rel="3"><a href="#"><span>3</span></a></li>
            <li rel="4"><a href="#"><span>4</span></a></li>
            <li rel="5"><a href="#"><span>5</span></a></li>
        </ol>
    </span>

    I know that it's not possible to change the numeric controls a lot, but you can always use customLinks (see below), if you want more freedom.

    customLink

    The customLink option is really interesting, because by using it, you have 100% freedom over the HTML of the controls.

    The value that goes into the customLink option, is a CSS selector, that targets the HTML you want to be a control.
    To be precise, it's jQuery selector, but just use it as an normal CSS selector.

    I usually use a value like customLink: 'a.customlink', to select links with the class "customlink" to be my controls.
    Remember that anything can be used, it doesn't have to be a link. And remember that one doesn't exclude the other, you can use ordinary controls and customLinks at the same time.

    But we also need to tell the slider what to do, that's done using the rel tag like this:

    <a class="customlink" rel="next">
        This link makes the slider go to the next slide
    </a>

    The possible values of the rel attribute are:

    • stop stops an automatic slideshow (if it is currently running).
    • start starts an automatic slideshow.
    • block blocks the slider from getting any user input.
    • unblock unblocks the slider.
    • next go to the next slide.
    • prev go to the previous side.
    • first go to the first slide.
    • last go to the last slide.
    • [number] go to the slide specified using a number. Instead of [number] you insert a number (like '1').

    A customlink can the anything, even the slider itself. (I here assume that the option customLink is set to 'li.customlink')

    <div id="slider">
        <ul>
            <li class="customlink" rel="3">Content</li>
            <li>Content</li>
            <li>Content</li>
            <li>Content</li>
            <li>Content</li>
        </ul>
    </div>

    That code will make the slider animate to the third slide, when you click anywhere on the first slide.

    Now you should know how to make the HTML and CSS for Sudo Slider, next is the animations.

    Animate the controls

    As you might have noticed, the numeric buttons in the demo change color when a buttons corresponding slide is selected.
    This happens because the numeric buttons gets a "current" class added (and removed later, when the button no longer matches the current slide).

    As always with controls, remember that there's no difference between customLinks and "normal" controls, everything explained here works on both.

    But there's also a function that fires when an numeric control gets the "current" class, and when it's removed.
    They are: currentFunc and uncurrentFunc
    And with them, you can make any animation with the numeric controls.

    I got a quick demo that uses them both.

    This all happens after the animation is complete (at least with the default settings, it can be changed using the updateBefore option).

    If you want to animate the next/previous/first/last buttons, then you can use the beforeAniFunc and afterAniFunc
    It could look something like this:

     
    $(document).ready(function(){	
        var sudoSlider = $("#slider").sudoSlider({ 
            prevNext: true,
            numeric: false,
            beforeAniFunc: function(t){ 
                $('.nextBtn').stop().fadeTo(300, 0.3);
                $('.prevBtn').stop().fadeTo(300, 0.3);
            },
            afterAniFunc: function(t){ 
               if (t != 5) $('.nextBtn').stop().fadeTo(500, 1);
               if (t != 1) $('.prevBtn').stop().fadeTo(500, 1);
            }
        });
    });
    	

Help and support

If you need help, the first thing you should do is read the documentation.
Start with reading howto setup the slider if you are completely lost.
If that doesn't help, try reading the rest of the documentation.

Donate to the project

I like my work, like to see a piece of code grow.
But humans doensn't live of air alone.
So if you like my creation, you should consider giving me a cup of coffee.

See the demos

The demos showcase just how much Sudo Slider can do.
They showcase features such as AJAX, fading, callbacks, captions automatic slidehow and a creative navigation.