JQuery 带有 table 和图像的滑块

JQuery Slider with table and image

我是 jQuery 的新手。所以我不知道如何完美地解决这个问题,但这里有一排图片,我需要让它像滑块一样无限循环 运行 。找了很多地方,无奈return。我该怎么做?

<table id="boxes" style="border: 1px solid #666;">
   <tr>
       <td>
           <img src="images/image1.jpg" width="173" height="110" class="imgborder" />           
           <img src="images/image2.jpg" width="173" height="110" class="imgborder" />   
           <img src="images/image3.jpg" width="173" height="110" class="imgborder" />   
           <img src="images/image4.jpg" width="173" height="110" class="imgborder" />   
           <img src="images/image5.jpg" width="173" height="110" class="imgborder" />    
           <img src="images/image6.jpg" width="173" height="110" class="imgborder" />   
           <img src="images/image7.jpg" width="173" height="110" class="imgborder" />
       </td>
   </tr>
</table>

尝试jQuery循环。这是我所知道的最简单的。 http://jquery.malsup.com/cycle/

我认为插件是个好主意。如果您希望图像行像股票代码一样滚动,您可以使用 jQuery SimpleScroll. If you want a standard slideshow you could try a lightweight image slider like Nivo Slider

如果您不想使用任何插件,那么试试这个简单的 jQuery Slider

<style type="text/css">
    #boxes img {
        display: none;
    }

    #boxes .active {
        display: block !important;
    }
</style>

<table id="boxes" style="border: 1px solid #666;">
    <tr>
        <td> <img src="res/i/img.jpg" width="173" height="110" class="imgborder" /> <img src="res/i/revamp/ajax-loader.gif" width="173" height="110" class="imgborder" /> <img src="res/i/revamp/yellowspike.gif" width="173" height="110" class="imgborder" /> </td>
    </tr>
</table>
<script src="res/js/rvmp_admin/jquery/jquery.js" type="text/javascript"></script>
<script type="text/javascript">
    $(document).ready(function() {
        $("#boxes img:first").addClass('active');
        setInterval(function() {
            InitializeSlider();
        }, 3000);

        function InitializeSlider() {
            if($("#boxes img").hasClass('active')) {
                var nextImg;
                if(($("#boxes .active").index() + 1) == $("#boxes img").length) {
                    nextImg = $("#boxes img:first");
                } else {
                    nextImg = $("#boxes .active").next();
                }
                $("#boxes .active").hide("slow").removeClass("active");
                nextImg.addClass('active');
            } else {
                $("#boxes img:first").addClass('active');
            }
        }
    });
</script>