Пользовательский интерфейс вкладок jQuery: изменение двух разных атрибутов данных при изменении вкладки - PullRequest
1 голос
/ 02 июня 2011

Я могу поменять местами изображение в div при каждом изменении вкладки в соответствии с атрибутом данных в html каждой вкладки.Но я также хочу изменить другой div для кредита фотографа, и я не делаю что-то правильно, хотя это должно быть легко. jsfiddle здесь: http://jsfiddle.net/8muBm/56/

$("#tabs").tabs({
    select: function($event, ui) { /* Extract the image from the active tab: */
        var img = $(ui.panel).data("image");

        /* Animate the header out, set the background css, then animate back in: */

        $("#headerwrapper").animate({
            opacity: 'toggle'
        }, function() {
            $(this).css("background-image", "url(" + img + ")").animate({
                opacity: 'toggle'
            });

            /* credit changer */

            $("#photocredit").text($(this).attr("data-credit"));

        });
    }
});

1 Ответ

2 голосов
/ 02 июня 2011

Я думаю, ваш $ (this) указывает на тег div "headerwrapper".

Попробуйте:

$("#tabs").tabs({
    select: function($event, ui) { /* Extract the image from the active tab: */
    var img = $(ui.panel).data("image");

    /* Animate the header out, set the background css, then animate back in: */

    $("#headerwrapper").animate({
        opacity: 'toggle'
        }, function() {
            $(this).css("background-image", "url(" + img + ")").animate({
                opacity: 'toggle'
            });

            /* credit changer */

            $("#photocredit").text($(ui.panel).data("credit"));

        });
    }
});
...