html 使用Backstretch随机化幻灯片

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了html 使用Backstretch随机化幻灯片相关的知识,希望对你有一定的参考价值。

<script type="text/javascript" src="~/Style/js/jquery.backstretch.min.js"></script>

    <script type='text/javascript'>

        //using Backstretch to show a slideshow of sorts where the slideshow actually acts like the background image is random on refresh.

        var images = [
            'http://dl.dropbox.com/u/515046/www/outside.jpg',
            'http://dl.dropbox.com/u/515046/www/garfield-interior.jpg',
            'http://dl.dropbox.com/u/515046/www/cheers.jpg'
        ];
        // The index variable will keep track of which image is currently showing
        var index = 0,oldIndex;

        $(document).ready(function() {
    
            // Call backstretch for the first time,
            // In this case, I"m settings speed of 500ms for a fadeIn effect between images.
            index = Math.floor((Math.random()*images.length));
            $.backstretch(images[index], {
                speed: 1000
            });

            // Set an interval that increments the index and sets the new image
            // Note: The fadeIn speed set above will be inherited
            //	
            
            setInterval(function() {
               oldIndex = index;
                while (oldIndex == index) {
                    index = Math.floor((Math.random()*images.length));
                }
                $.backstretch(images[index]);
            }, 99999);

            // A little script for preloading all of the images
            // It"s not necessary, but generally a good idea
            $(images).each(function() {
                $("<img/>")[0].src = this;
            });
    
        });

    </script>

以上是关于html 使用Backstretch随机化幻灯片的主要内容,如果未能解决你的问题,请参考以下文章

Backstretch jQuery 点导航

php Image Widget Plus - 随机化所有幻灯片的顺序

php Image Widget Plus - 随机化所有幻灯片的顺序

幻灯片不显示左/右箭头

css 超简单的jQuery背景图像随机幻灯片(使用CSS3进行转换,并通过HTML5`data`属性获取图像路径)。

动态背景插件Backstretch