Perform function in attr() callback?

前端 未结 2 1410
甜味超标
甜味超标 2021-01-06 10:24

Not sure if I am doing this correctly or not.

Here is my .js:

var currentIMG;
$( \'.leftMenuProductButton\' ).hover(function () {

              


        
2条回答
  •  被撕碎了的回忆
    2021-01-06 10:39

    You can do this with the load event like this:

    $("#swapImg").css("opacity", 0).attr("src", productImages[swapIMG])
                 .one("load",function(){ //fires (only once) when loaded
                    $(this).fadeIn("slow");
                 }).each(function(){
                    if(this.complete) //trigger load if cached in certain browsers
                      $(this).trigger("load");
                 });
    

    The fade will start after the image load event fires.

提交回复
热议问题