幻灯片显示如何自动更改幻灯片

时间:2012-07-09 12:00:15

标签: javascript jquery css slider

我在我的网站上添加了一个Jquery滑块(称为SudoSlider),带有“上一个”和“下一个”按钮,允许用户前进到下一张幻灯片,或者返回一个。但是,我想制作幻灯片以自动更改。

我遇到过与此类似的问题,但我的Javascript相当有限,所以我无法使用提供给其他用户的代码。

如果有人能帮我实现这一目标,我将非常感激。

请在此处查看此JSFiddle以了解所使用的代码。

此外,如果JSFiddle没用,可以在动作here中看到滑块。

非常感谢!

2 个答案:

答案 0 :(得分:1)

这是工作小提琴:http://jsfiddle.net/surendraVsingh/VN7F8/1/

我刚刚更改了加载javascript的顺序。以下是包含javascript的完整HTML和&包括外部css你有。

HTML更改:

<html>
  <head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"/></script>
<script type="text/javascript" src="http://www.pinknoise-systems.co.uk/userfiles/jquery/slider/js/jquery.sudoSlider.min.js"/></script>
<script type="text/javascript">
    $(document).ready(function(){    
            var sudoSlider = $("#slider").sudoSlider();
     });    
</script>
</head>
<body>
<div id="container">
    <div style="position:relative;">
        <div id="slider">
            <ul>                
                <li>
                    <div style="margin:0 auto;text-align:center;height:300px;">
                        <img src="http://www.pinknoise-systems.co.uk/userfiles/images/final_slide_6.png" />
                    </div>
                </li>
                <li>
                    <div style="margin:0 auto;width:620px;height:300px;background:url('http://www.pinknoise-systems.co.uk/userfiles/images/final_slide_5.png');">

                    <div class="product_row_1">
                        <div class="one">
                        <a href="http://www.pinknoise-systems.co.uk/Sennheiser_SKP_300_G3--product--1091.html" class="slide_product_name">Sennheiser SKP 300 G3</a>
                        <div class="p-image"><a href="http://www.pinknoise-systems.co.uk/Sennheiser_SKP_300_G3--product--1091.html"><img src="http://www.pinknoise-systems.co.uk/userfiles/images/monthly/skp300.jpg" /></a></div>
                        <div class="p-content">
                            <img src="http://www.pinknoise-systems.co.uk/userfiles/images/monthly/4_stars.png" />
                            <p class="slide_product_price">£296.00</p>
                             <p class="slide_product_price2">EX VAT @20%</p>
                        </div>
                        </div>

                        <div class="two margin-3">
                         <a href="http://www.pinknoise-systems.co.uk/Fostex_PM841_Professional_Studio_Monitor--product--1110.html" class="slide_product_name">Fostex PM8.4.1</a>
                        <div class="p-image"><a href="href="http://www.pinknoise-systems.co.uk/Fostex_PM841_Professional_Studio_Monitor--product--1110.html""><img src="http://www.pinknoise-systems.co.uk/userfiles/images/monthly/pm841.jpg" /></a></div>
                        <div class="p-content">
                            <img src="http://www.pinknoise-systems.co.uk/userfiles/images/monthly/4_stars.png" />
                            <p class="slide_product_price">£412.50</p>
                           <p class="slide_product_price2">EX VAT @20%</p>
                        </div>
                        </div>

                        <div class="three margin-3">
                         <a href="http://www.pinknoise-systems.co.uk/Delkin_Wingman_HD_3oz_Waterproof_Action_Camera--product--850.html" class="slide_product_name">Delkin Wingman</a>
                        <div class="p-image"><a href="http://www.pinknoise-systems.co.uk/Delkin_Wingman_HD_3oz_Waterproof_Action_Camera--product--850.html"><img src="http://www.pinknoise-systems.co.uk/userfiles/images/monthly/wingman.jpg" /></a></div>
                        <div class="p-content">
                            <div class="4stars"><img src="http://www.pinknoise-systems.co.uk/userfiles/images/monthly/4_stars.png" /></div>
                            <p class="slide_product_price">£179.19</p>
                            <p class="slide_product_price2">EX VAT @20%</p>
                        </div>
                        </div>

                    </div>


                    <div class="product_row_2">
                        <div class="one">
                        <a href="http://www.pinknoise-systems.co.uk/DFocus_Street_Runner_Bundle--product--1104.html" class="slide_product_name">D|Focus Street Runner Kit</a>
                        <div class="p-image"><a href="http://www.pinknoise-systems.co.uk/DFocus_Street_Runner_Bundle--product--1104.html"><img src="http://www.pinknoise-systems.co.uk/userfiles/images/monthly/streetrunnerbundle.jpg" /></a></div>
                        <div class="p-content">
                            <div class="4stars"><img src="http://www.pinknoise-systems.co.uk/userfiles/images/monthly/4_stars.png" /></div>
                            <p class="slide_product_price">£332.50</p>
                            <p class="slide_product_price2">EX VAT @20%</p>
                        </div>
                        </div>

                        <div class="two margin-3">
                         <a href="http://www.pinknoise-systems.co.uk/DFocus_Field_Runner_Bundle--product--1105.html" class="slide_product_name">D|Focus Field Runner Kit</a>
                        <div class="p-image"><a href="http://www.pinknoise-systems.co.uk/DFocus_Field_Runner_Bundle--product--1105.html"><img src="http://www.pinknoise-systems.co.uk/userfiles/images/monthly/fieldrunnerkit.jpg" /></a></div>
                        <div class="p-content">
                            <div class="4stars"><img src="http://www.pinknoise-systems.co.uk/userfiles/images/monthly/4_stars.png" /></div>
                            <p class="slide_product_price">£382.50</p>
                             <p class="slide_product_price2">EX VAT @20%</p>
                        </div>
                        </div>

                        <div class="three margin-3">
                         <a href="http://www.pinknoise-systems.co.uk/DFocus_Austin_Rig_Bundle--product--1106.html" class="slide_product_name">D|Focus Austin Rig Bundle</a>
                        <div class="p-image"><a href="http://www.pinknoise-systems.co.uk/DFocus_Austin_Rig_Bundle--product--1106.html"><img src="http://www.pinknoise-systems.co.uk/userfiles/images/monthly/austinrigbundle.jpg" /></a></div>
                        <div class="p-content">
                            <img src="http://www.pinknoise-systems.co.uk/userfiles/images/monthly/4_stars.png" />
                            <p class="slide_product_price">£499.17</p>
                            <p class="slide_product_price2">EX VAT @20%</p>
                        </div>
                        </div>

                    </div>

                    </div>
                </li>    
            <li>
                    <div style="margin:0 auto;text-align:center;">
                        <img src="http://www.pinknoise-systems.co.uk/userfiles/images/final_slide_3.jpg" />
                    </div>
                </li>

                <li>
                    <div style="margin:0 auto;text-align:center;">
                        <img src="http://www.pinknoise-systems.co.uk/userfiles/images/final_slide_4.jpg" />
                    </div>
                </li>
            </ul>
        </div>
    </div>
    </div>
</body>
</html>

答案 1 :(得分:0)

试试这个,它会将滑块设置为自动更改。

   $(document).ready(function(){    
        var sudoSlider = $("#slider").sudoSlider({fade: true,auto:true});
    });  

这是working link