代码之家  ›  专栏  ›  技术社区  ›  eozzy

简单股票代码(jQuery)

  •  0
  • eozzy  · 技术社区  · 15 年前
    <ul>
        <li><a href="#">one</a></li>
        <li><a href="#">two</a></li>
        <li><a href="#">three</a></li>
    </ul>
    

    我只想展示一个 li 一次使用幻灯片效果,就是这样。我想避免在这么简单的事情上使用插件。

    事先谢谢你的帮助。

    2 回复  |  直到 15 年前
        1
  •  4
  •   meo    13 年前

    我为你做了一些简单的事情(基于你的描述),只是为了给你指出正确的方向:

    在这里查看: 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
    
        2
  •  1
  •   Mathew    15 年前