如何创建 jquery li 旋转器

发布于 2024-10-18 03:06:23 字数 2925 浏览 4 评论 0原文

我的想法是创建一个包含图像的列表,首先隐藏所有项目,然后显示第一个项目,然后重复隐藏当前的 li,然后显示下一个项目。然后,当到达最后一个项目时,它将隐藏它,然后显示第一个项目并重新开始该过程。


在文档上(准备好)我希望发生以下情况:

  1. 隐藏所有项目
  2. 显示第一个项目
  3. 重复
    1. 延迟
    2. 如果在最后(隐藏此项/显示第一项
    3. if else(隐藏此项/显示下一项
  4. onclick (nextbutton)
    1. 如果在最后(隐藏此项/显示第一项
    2. if else(隐藏此项/显示下一项
  5. onclick (prevbutton)
    1. 如果在第一个(隐藏此项/显示最后一项)
    2. if else(隐藏此项/显示上一项)

这是我正在使用的列表:

<ul id="rotator">
    <li class="rimage"><img /></li>
    <li class="rimage"><img /></li>
    <li class="rimage"><img /></li>
</ul>

我还想要一个左右按钮,可以在不同的项目之间切换项目。

另外,如果有人愿意的话,是否可以使其在图像中向左或向右滑动?

谢谢!

更新:

现在我想起来了,我可能不应该在不包含我拥有的代码的情况下问这个问题,我只是认为我做错了,无论如何,这就是我到目前为止所做的:

PS:我真的你可能知道,对于 Javascript 很陌生......

$(document).ready(function(){
    $('.rimage').hide(function(){
        $('.rimage:first').fadeIn(100, function(){
            var a = 0;
            var mouseover = false;

            $('#rotator').mouseover(function(){
                mouseover = true;
            });
            $('#rotator').mouseout(function(){
                mouseover = false;
            });


            //BEGIN LOOP
            while (a != 1 && mouseover == false){
                if(this == last){
                    $(this).hide("slide", {direction: "up"}, 400, function(){
                        $('.rimage:first').show("slide", {direction: "up"}, 400);
                    });
                };
                else{
                    $(this).hide("slide", {direction: "up"}, 400, function(){
                        $(this).next().show("slide", {direction: "up"}, 400);
                    });
                };
            };
            //END LOOP

            //BUTTONS

            //NEXT BUTTON
            $('rightarrow').click(function(){
                if(this, '.rimage:last'){
                    $(this).hide("slide", {direction: "up"}, 400, function(){
                        $('.rimage:first').show("slide", {direction: "up"}, 400);
        });
        };
        else{
            $(this).hide("slide", {direction: "up"}, 400, function(){
                $(this).next().show("slide", {direction: "up"}, 400);
            });
            };
    });

    //PREV BUTTON
    $('leftarrow').click(function(){
        if(this, '.rimage:first'){
            $(this).hide("slide", {direction: "down"}, 400, function(){
                $('.rimage:last').show("slide", {direction: "down"}, 400);
        });
            };
        else{
            $(this).hide("slide", {direction: "down"}, 400, function(){
                $(this).next().show("slide", {direction: "down"}, 400);
        });
        };
         });

     //END BUTTONS
        });
    });
});

My idea was to create a list with images in it that would hide all the items first then show the first one, then repetitively hide the current li and then show the next one. Then when the last item was reached it would hide it then show the first and start the process over.


On the document(ready) i want the following to happen:

  1. hide all items
  2. show first item
  3. repeat
    1. delay
    2. if on last (hide this item / show first item
    3. if else (hide this item / show next item
  4. onclick (nextbutton)
    1. if on last (hide this item / show first item
    2. if else (hide this item / show next item
  5. onclick (prevbutton)
    1. if on first (hide this item / show last item)
    2. if else (hide this item / show prev item)

here's the list I'm using:

<ul id="rotator">
    <li class="rimage"><img /></li>
    <li class="rimage"><img /></li>
    <li class="rimage"><img /></li>
</ul>

I also would like a left and right button that would switch between the different items.

Also as a bonus if anyone is willing is it possible to make it slide left or right through the images?

Thanks!

UPDATE:

Well now that I think of it, I probably shouldn't ask this without including the code I have, I just thought I was doing it all wrong anyways this is what I've done so far:

PS: I'm really new to Javascript as you probably can tell...

$(document).ready(function(){
    $('.rimage').hide(function(){
        $('.rimage:first').fadeIn(100, function(){
            var a = 0;
            var mouseover = false;

            $('#rotator').mouseover(function(){
                mouseover = true;
            });
            $('#rotator').mouseout(function(){
                mouseover = false;
            });


            //BEGIN LOOP
            while (a != 1 && mouseover == false){
                if(this == last){
                    $(this).hide("slide", {direction: "up"}, 400, function(){
                        $('.rimage:first').show("slide", {direction: "up"}, 400);
                    });
                };
                else{
                    $(this).hide("slide", {direction: "up"}, 400, function(){
                        $(this).next().show("slide", {direction: "up"}, 400);
                    });
                };
            };
            //END LOOP

            //BUTTONS

            //NEXT BUTTON
            $('rightarrow').click(function(){
                if(this, '.rimage:last'){
                    $(this).hide("slide", {direction: "up"}, 400, function(){
                        $('.rimage:first').show("slide", {direction: "up"}, 400);
        });
        };
        else{
            $(this).hide("slide", {direction: "up"}, 400, function(){
                $(this).next().show("slide", {direction: "up"}, 400);
            });
            };
    });

    //PREV BUTTON
    $('leftarrow').click(function(){
        if(this, '.rimage:first'){
            $(this).hide("slide", {direction: "down"}, 400, function(){
                $('.rimage:last').show("slide", {direction: "down"}, 400);
        });
            };
        else{
            $(this).hide("slide", {direction: "down"}, 400, function(){
                $(this).next().show("slide", {direction: "down"}, 400);
        });
        };
         });

     //END BUTTONS
        });
    });
});

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

终弃我 2024-10-25 03:06:23

您目前的代码有问题吗? Stackoverflow 并不是一个只提供代码项目并让其他人完成的地方。

这是一个很好的教程,介绍如何使用 Jquery 和您拥有的相同标记创建自己的教程。

http://tutorialzine.com/2010/11/rotating-slideshow-jquery- CSS3/

Are you currently having issues with your code? Stackoverflow isnt a place to just drop off code projects and have them completed by someone else.

Here is a good tutorial on creating your own using Jquery with the same markup you have.

http://tutorialzine.com/2010/11/rotating-slideshow-jquery-css3/

霊感 2024-10-25 03:06:23

您也可以看看这个 jQuery 插件。我以前用过它并且很容易实现。
http://sorgalla.com/projects/jcarousel/

You might also take a look at this plugin for jQuery. I've used it before and it's easy to implement.
http://sorgalla.com/projects/jcarousel/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文