开发者

Jquery fade in / out looping more than once

开发者 https://www.devze.com 2023-01-08 09:39 出处:网络
I\'ve been using jquery to do some image swapping and fading. I have a div, with and id of cup-builder-error

I've been using jquery to do some image swapping and fading.

I have a div, with and id of cup-builder-error

I use jquery to load images into divs, then on error fade in and out the error div

$("#imgShell").attr("src","products/components/" + idArray[2] + ".png").error(
                                        function(){
                                            $("#cup-bui开发者_开发技巧lder-error").fadeIn('fast');                                             
                                            $("#cup-builder-error").fadeOut('slow');
                                        });

that code is surrounded by $("a").click( function(event){

What happens is the fade in / out routine loops the number of time that the error happens.

What did I do wrong?

Thanks for the help!


Each time the "a" is clicked, a new error event is being bound. You only need to do it once.

$('#imgShell').error(function () {
    $("#cup-builder-error").fadeIn('fast');                                             
    $("#cup-builder-error").fadeOut('slow');
});

$('a').click(function (event) {
    $('#imgShell').attr("src","products/components/" + idArray[2] + ".png");

    event.preventDefault();
});
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号