2011-06-02 75 views
1

根據每個選項卡的html中的數據屬性,我可以在每個選項卡更改的div中交換圖像。但我也想改變另一個攝影師的功勞,儘管應該很簡單,但我沒有做正確的事情。 的jsfiddle這裏:http://jsfiddle.net/8muBm/56/jQuery選項卡UI:更改選項卡更改的兩個不同的數據屬性

$("#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")); 

     }); 
    } 
}); 

回答

2

我覺得你的$(這)是指向格 「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")); 

     }); 
    } 
}); 
+0

偉大的作品,謝謝。 – markratledge 2011-06-02 14:27:30