幻灯片中淡入图像?

时间:2013-11-18 18:19:21

标签: javascript jquery html css fadein

请看这个小提琴http://jsfiddle.net/rabelais/ayaK2/

  1. 以下是图片和视频的幻灯片。

  2. 所有图片和视频均为全屏。

  3. 当用户点击每个图片/视频时,它会显示下一个。

  4. 我的问题:如何让幻灯片中的图像淡入?

    $(function () {
    
    var win = $(window),
        fullscreen = $('.full'),
        image = fullscreen.find('img, video'),
        imageWidth = image.width(),
        imageHeight = image.height(),
        imageRatio = imageWidth / imageHeight,
        currentSlide = 0,
        numSlides = $('.full').length;
    
    function resizeImage() {
        var winWidth = win.width(),
            winHeight = win.height(),
            winRatio = winWidth / winHeight;
    
        if (winRatio > imageRatio) {
            image.css({
                width: winWidth,
                height: Math.round(winWidth / imageRatio)
            });
        } else {
            image.css({
                width: Math.round(winHeight * imageRatio),
                height: winHeight
            });
        }
    }
    
    function advanceToSlide(slidePos){
        slide = $('.full').eq(slidePos);
        slide.show();
        var video = $('video', slide);
    
        $('video').each(function(){
            $(this).get(0).pause();
        })
    
        if(video.length){
            console.log(video.get(0).play());
        }   
    }
    
    $('.full').on('click', function(){
        $('.full').hide();
        if(currentSlide < numSlides - 1){
            currentSlide = currentSlide + 1;
        } else{
            currentSlide = 0;
        }
        advanceToSlide(currentSlide);
    });
    
    $('.full:gt(0)').hide();
    resizeImage();
    
    });
    

1 个答案:

答案 0 :(得分:0)

http://jsfiddle.net/isherwood/ayaK2/2

function advanceToSlide(slidePos){
    slide = $('.full').eq(slidePos);
    slide.fadeIn();
    ....