简体   繁体   English

幻灯片:在JQuery上淡入和淡出

[英]Slideshow: Fade in and Fade out on JQuery

I am creating a slideshow using JQuery. 我正在使用JQuery创建幻灯片。 Slideshow works with the code below: 幻灯片可与以下代码一起使用:

     function playSlideshow() {

            timer = setInterval(function () {

            thumbnails.children[currentNum].className = '';

                currentNum++;
                if (currentNum > data.files.length - 1) {
                    currentNum = 0;
                    console.log(currentNum);
                }

                var currentImage = data.files[currentNum];
                target.src = currentImage;

                thumbnails.children[currentNum].className = 'current';
               //playSlideshow();
            }, 3000);                
        }

However, I got an error (currentImage.fadeIn is not a function) once I inserted the lines of codes below: 但是,一旦我插入下面的代码行,我就会收到一个错误(currentImage.fadeIn不是一个函数):

    function playSlideshow() {

        timer = setInterval(function () {

            thumbnails.children[currentNum].className = '';

            $('#main>img').fadeOut('slow');

            currentNum++;
            if (currentNum > data.files.length - 1) {
                currentNum = 0;
            }

            var currentImage = data.files[currentNum];
          //var image = data.files[currentNum].clone(true);
            $('#main>img').prepend(currentImage.fadeIn('slow'));
            target.src = currentImage;

            thumbnails.children[currentNum].className = 'current';
           //playSlideshow();
        }, 3000);                
    }

I got the 'files' array from a JSON file using Ajax. 我使用Ajax从JSON文件中获取了“文件”数组。 Does anyone has an idea how to fix this? 有谁知道如何解决这个问题?

Try 尝试

$('#main>img').prepend(currentImage).fadeIn('slow');

Fade on the jQuery object, not the array object. 淡入jQuery对象,而不是数组对象。

currentImage.fadeIn is not a function is telling you that either currentImage is not a jQuery object, or fadeIn doesn't exist in the jQuery namespace. currentImage.fadeIn is not a function它告诉您currentImage不是jQuery对象,或者jQuery名称空间中不存在fadeIn。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM