随机播放滑块显示

发布于 2024-10-30 07:42:13 字数 4431 浏览 1 评论 0原文

我的网站滑块有问题,尽管滑块工作得很好,但我需要它是随机的或随机播放的,而不是显示有序的内容。 我已经有了代码,需要一些修改。

这是主 file.php 上的行,

<script type="text/javascript">
$(document).ready(function() {
    $('#slider1').s3Slider({

        timeOut: 8000

    });
});

<div id="slider1">
    <ul id="slider1Content">
        <li class="slider1Image">
            <a href="goo.com"><img src="products/1.png" alt="1" /></a>
            <span class="left">
            caption1 
            </span>
        </li>

        <li class="slider1Image">
            <a href=""><img src="products/2.png" alt="2" /></a>
            <span class="right">caption2
            </span>
        </li>

        <li class="slider1Image">
            <a href=""><img src="products/3.png" alt="3" /></a>
            <span class="right">caption3. 
            </span>
        </li></div>

这是 java 脚本文件,

(function($){  

$.fn.s3Slider = function(vars) {       



    var element     = this;
    var timeOut     = (vars.timeOut != undefined) ? vars.timeOut : 4000;
    var current     = null;
    var timeOutFn   = null;
    var faderStat   = true;
    var mOver       = false;
    var items       = $("#" + element[0].id + "Content ." + element[0].id + "Image");
    var itemsSpan   = $("#" + element[0].id + "Content ." + element[0].id + "Image span");

    items.each(function(i) {

        $(items[i]).mouseover(function() {
           mOver = true;
        });

        $(items[i]).mouseout(function() {
            mOver   = false;
            fadeElement(true);

        });

    });

    var fadeElement = function(isMouseOut) {
        var thisTimeOut = (isMouseOut) ? (timeOut/2) : timeOut;
        thisTimeOut = (faderStat) ? 10 : thisTimeOut;
        if(items.length > 0) {
            timeOutFn = setTimeout(makeSlider, thisTimeOut);
        } else {
            console.log("Poof..");
        }
    }

    var makeSlider = function() {

        current = (current != null) ? current : items[(items.length-1)];
        var currNo      = jQuery.inArray(current, items) + 1
        currNo = (currNo == items.length) ? 0 : (currNo - 1);
        var newMargin   = $(element).width() * currNo;
        if(faderStat == true)

        {
            if(!mOver) {
                $(items[currNo]).fadeIn((timeOut/6), function() {
                    if($(itemsSpan[currNo]).css('bottom') == 0) {
                        $(itemsSpan[currNo]).slideUp((timeOut/6), function() {
                            faderStat = false;
                            current = items[currNo];
                            if(!mOver) {
                                fadeElement(false);
                            }
                        });
                    } else {
                        $(itemsSpan[currNo]).slideDown((timeOut/6), function() {
                            faderStat = false;
                            current = items[currNo];
                            if(!mOver) {
                                fadeElement(false);
                            }
                        });
                    }
                });
            }
        } else {
            if(!mOver) {
                if($(itemsSpan[currNo]).css('bottom') == 0) {
                    $(itemsSpan[currNo]).slideDown((timeOut/6), function() {
                        $(items[currNo]).fadeOut((timeOut/6), function() {
                            faderStat = true;
                            current = items[(currNo+1)];
                            if(!mOver) {
                                fadeElement(false);
                            }
                        });
                    });
                } else {
                    $(itemsSpan[currNo]).slideUp((timeOut/6), function() {
                    $(items[currNo]).fadeOut((timeOut/6), function() {
                            faderStat = true;
                            current = items[(currNo+1)];
                            if(!mOver) {
                                fadeElement(false);
                            }
                        });
                    });
                }
            }
        }
    }

    makeSlider();

};})(jQuery);    

我在修改这个脚本上花了将近一周的时间......请帮助

i have a problem on the slider of my site, though the slider works fine and good but i need it to be random or shuffle instead of displaying an ordered content..
i already have the code and it need some modification.

this is the line on the main file.php

<script type="text/javascript">
$(document).ready(function() {
    $('#slider1').s3Slider({

        timeOut: 8000

    });
});

<div id="slider1">
    <ul id="slider1Content">
        <li class="slider1Image">
            <a href="goo.com"><img src="products/1.png" alt="1" /></a>
            <span class="left">
            caption1 
            </span>
        </li>

        <li class="slider1Image">
            <a href=""><img src="products/2.png" alt="2" /></a>
            <span class="right">caption2
            </span>
        </li>

        <li class="slider1Image">
            <a href=""><img src="products/3.png" alt="3" /></a>
            <span class="right">caption3. 
            </span>
        </li></div>

this is the java script file

(function($){  

$.fn.s3Slider = function(vars) {       



    var element     = this;
    var timeOut     = (vars.timeOut != undefined) ? vars.timeOut : 4000;
    var current     = null;
    var timeOutFn   = null;
    var faderStat   = true;
    var mOver       = false;
    var items       = $("#" + element[0].id + "Content ." + element[0].id + "Image");
    var itemsSpan   = $("#" + element[0].id + "Content ." + element[0].id + "Image span");

    items.each(function(i) {

        $(items[i]).mouseover(function() {
           mOver = true;
        });

        $(items[i]).mouseout(function() {
            mOver   = false;
            fadeElement(true);

        });

    });

    var fadeElement = function(isMouseOut) {
        var thisTimeOut = (isMouseOut) ? (timeOut/2) : timeOut;
        thisTimeOut = (faderStat) ? 10 : thisTimeOut;
        if(items.length > 0) {
            timeOutFn = setTimeout(makeSlider, thisTimeOut);
        } else {
            console.log("Poof..");
        }
    }

    var makeSlider = function() {

        current = (current != null) ? current : items[(items.length-1)];
        var currNo      = jQuery.inArray(current, items) + 1
        currNo = (currNo == items.length) ? 0 : (currNo - 1);
        var newMargin   = $(element).width() * currNo;
        if(faderStat == true)

        {
            if(!mOver) {
                $(items[currNo]).fadeIn((timeOut/6), function() {
                    if($(itemsSpan[currNo]).css('bottom') == 0) {
                        $(itemsSpan[currNo]).slideUp((timeOut/6), function() {
                            faderStat = false;
                            current = items[currNo];
                            if(!mOver) {
                                fadeElement(false);
                            }
                        });
                    } else {
                        $(itemsSpan[currNo]).slideDown((timeOut/6), function() {
                            faderStat = false;
                            current = items[currNo];
                            if(!mOver) {
                                fadeElement(false);
                            }
                        });
                    }
                });
            }
        } else {
            if(!mOver) {
                if($(itemsSpan[currNo]).css('bottom') == 0) {
                    $(itemsSpan[currNo]).slideDown((timeOut/6), function() {
                        $(items[currNo]).fadeOut((timeOut/6), function() {
                            faderStat = true;
                            current = items[(currNo+1)];
                            if(!mOver) {
                                fadeElement(false);
                            }
                        });
                    });
                } else {
                    $(itemsSpan[currNo]).slideUp((timeOut/6), function() {
                    $(items[currNo]).fadeOut((timeOut/6), function() {
                            faderStat = true;
                            current = items[(currNo+1)];
                            if(!mOver) {
                                fadeElement(false);
                            }
                        });
                    });
                }
            }
        }
    }

    makeSlider();

};})(jQuery);    

i am struggling modifying this script for almost a week ... please help

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

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

发布评论

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

评论(1

鱼窥荷 2024-11-06 07:42:13

不确定您是否仍在寻找解决方案...我刚刚完成了此操作,但认为通过从随机数组调用 li 标签将它们写出服务器端将是更好的方法。那就是如果您使用服务器端脚本 - 下面是我在 php 中所做的。

$arr = 数组("
一些文字“,”
一些文字“,”
一些文字",);

        $arrCnt = count($arr);
 for ($i=0; $i<=$arrCnt; $i++)
        {

            $random = array_rand($arr);

          echo "
  • "; 回声 $arr[$随机]; echo "
  • \n"; if($i<$arrCnt-1) 取消设置($arr[$random]); } ?>

    希望有帮助。

    Not sure if your still looking for a solution... I've just done this, but thought it would have been a better method to write the li tags out server side by calling them from a random array. That's if your using server side scriptiing - Below is what I did in php.

    $arr = array("
    Some text", "
    Some text", "
    Some text", );

            $arrCnt = count($arr);
    
            for ($i=0; $i<=$arrCnt; $i++)
            {
    
                $random = array_rand($arr);
    
              echo "<li class='sliderImage'>";
                echo $arr[$random];
              echo "</li>\n";   
    
              if($i<$arrCnt-1)
                  unset($arr[$random]);
            }
        ?>
    

    Hope that helps.

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