首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >简单记事本(jQuery)

简单记事本(jQuery)
EN

Stack Overflow用户
提问于 2010-05-10 15:44:51
回答 2查看 3K关注 0票数 0
代码语言:javascript
复制
<ul>
    <li><a href="#">one</a></li>
    <li><a href="#">two</a></li>
    <li><a href="#">three</a></li>
</ul>

我只想使用幻灯片效果一次只显示一个li,仅此而已。我想避免在这么简单的事情上使用插件。

提前感谢您的帮助。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2010-05-10 16:50:22

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

点击这里查看:http://jsfiddle.net/meo/ACenH/234/

代码语言:javascript
复制
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
票数 4
EN

Stack Overflow用户

发布于 2010-05-10 16:10:15

你的问题已经提到jquery是选择的javascript框架。你可以从jquery文档开始的最好的地方:

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

和滑动:

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

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

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2801072

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档