【问题标题】:Very short jQuery Image Slideshow非常短的 jQuery 图像幻灯片
【发布时间】:2013-11-27 01:19:32
【问题描述】:

我正在寻找使用 jQuery 创建渐变图像幻灯片的最短方法。 我在谷歌上找到的例子总是有很多不必要的特殊内容,我很难理解它们。 :/

幻灯片需要使用现有图像进行投射:

<img src="myImage.jpg"/>

使用以下图片:

imgArray = ["img1.jpg","img2.jpg","img3.jpg"]

这样做的最短/最简单的方法是什么?

【问题讨论】:

  • 首先做一些工作,如果您遇到任何问题,请在此处发布......

标签: javascript jquery html slideshow


【解决方案1】:

您可以点击此链接以非常少的代码创建图片幻灯片 背后的整个想法是滑动图像位置并在改变图像位置时使用变换效果。

http://jforjs.com/creating-image-slider-html-css-without-plugin/

好在你可以创建一个面向对象的代码(jquery pluing),也可以用几行代码创建多个图像幻灯片。

【讨论】:

    【解决方案2】:

    给你,在 15 分钟内完成...

    小提琴: http://jsfiddle.net/eEg3R/4/

    HTML:

    <img id="slide" src=""/>
    

    代码:

        var images = ['http://placehold.it/300x300/000','http://placehold.it/300x300/ddd','http://placehold.it/300x300/123456'];
    
    function slideshow(options) {
        var defaults ={
            fadeInSpeed:1000,
            fadeOutSpeed:1000,
            slideLength:4000
        }
    
        //merge options with defaults
        var settings= $.extend({},defaults,options);
        //get a reference to our image holder
        var $slide = $('#slide');
        //initialize the slide index
        var slideIndex=0;
    
        //begin the slideshow
        nextSlide();
    
        function nextSlide(){
            //load the new image...
            $slide[0].src = images[slideIndex];
            //show it
            $slide.fadeIn(settings.fadeInSpeed,function(){
                setTimeout(function(){
                    $slide.fadeOut(settings.fadeOutSpeed,nextSlide);
                    //increment index and reset to 0 when we have reached the end
                   slideIndex = ++slideIndex % images.length;
                },settings.slideLength); 
            });
        }
    }
    
    $(function(){
        //optionally pass in custom settings, or just run normal to use defaults...
        slideshow();    
    });
    

    【讨论】:

    • 这太棒了!非常感谢。
    【解决方案3】:

    希望下面的代码可以帮助到你,

    var imgArray = ["img1.jpg","img2.jpg","img3.jpg"];
    var i=0;
    setInterval(function(){
        $('div').fadeToggle(2000,function(){
            $(this).text(imgArray[i]);    
        });
        i++;
        if(imgArray.length==i-1){
            i=0;
        }     
    },2000);
    

    Demo

    【讨论】:

      【解决方案4】:

      您可以循环遍历您的数组,并在指定的持续时间内将 Jquery 的fadeIn 与fadeOut 结合使用。这将以指定的间隔淡入和淡出您的图像。

      http://api.jquery.com/fadeIn/

      http://api.jquery.com/fadeOut/

      【讨论】:

        猜你喜欢
        • 2013-01-23
        • 1970-01-01
        • 1970-01-01
        • 2010-11-04
        • 2017-12-31
        • 1970-01-01
        • 2017-01-08
        • 2011-08-23
        • 1970-01-01
        相关资源
        最近更新 更多