jQuery Change Image src with Fade Effect

后端 未结 4 441
旧时难觅i
旧时难觅i 2020-12-04 22:04

I\'m trying to create an effect where you click on a thumbnail image, and the link to the thumbnail will replace the main image, but fade it in. This is the code I\'m curren

4条回答
  •  攒了一身酷
    2020-12-04 22:22

    You have to make it fadeOut() first, or hide it.

    Try this :

    $(".thumbs a").click(function(e) {
        e.preventDefault();
        $imgURL = $(this).attr("href");
        $(".boat_listing .mainGallery")
            .fadeOut(400, function() {
                $(".boat_listing .mainGallery").attr('src',$imgURL);
            })
            .fadeIn(400);
    });
    

    It should fadeOut the image, then change the src when it's hidden, and then fadeIn.

    Here's a jsFiddle example.

    Edit: you can find a more recent & better solution in Sandeep Pal's anwser

提交回复
热议问题