eozzy
eozzy

Reputation: 68670

Simple Ticker (jQuery)

<ul>
    <li><a href="#">one</a></li>
    <li><a href="#">two</a></li>
    <li><a href="#">three</a></li>
</ul>

I'd like to show only one li at a time using slide effect, thats it. I'd like to avoid using plugins for something as simple as this.

Thanks in advance for your help.

Upvotes: 0

Views: 3104

Answers (2)

meo
meo

Reputation: 31249

i have made something simple up for you (based on your description), just to point you in the right direction:

check it out here: http://jsfiddle.net/meo/ACenH/234/

function slider(container, delay){
$container = $(container) // select the container elements and store them in a variable

if ( !$container.length ){ return fasle; } // checks if the slider exists in your dom. if not the function ends here...

    var slides = $container.length, // gives back the total LI's you have
        slide = 0 // set the actual li to show

        setInterval(function(){ // set a Interval for your main function
            if (slide == slides - 1) { // if the actual slide is equal the total slides (-1 because eq is 0 based and length gives back the number of elements in the jQuery object) the slide counter is set to 0
               $container.slideDown(); // and all slides a shown again
               slide = 0;
            } else {
              $container.eq(slide).slideUp(); //slides the selected slide up i think you could think of a solution with .next() instead of eq() 
              slide++; // slide counter +1
            }

        }, delay)

}

slider('ul > li', 2000); // call your slider function

Upvotes: 4

Mathew
Mathew

Reputation: 8279

Your question already mentions jquery as the javascript framework of choice. The best place you can start is the jquery docs on hiding:

http://api.jquery.com/hide/

and sliding:

http://api.jquery.com/slideUp/
http://api.jquery.com/slideDown/
http://api.jquery.com/slideToggle/

Upvotes: 1

Related Questions