Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
429 views
in Technique[技术] by (71.8m points)

javascript - jQuery - Change Image When Tab is Clicked

I am trying to get a WordPress image to change based on which tab is clicked.

I want the image to be replaced with a new image using jQuery's fade effect. The image must be relative to the tab.

Example...

If tab "my1" is clicked, then replace current images with my1.jpg If tab "my2" is clicked, then replace current images with my2.jpg

Any help, much appreciated :)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Here is a way to do what you want using jQuery UI tabs. It uses the "show" event to detect which ui.panel element is being displayed.

?$('#tabs').tabs({
  show: function(e,ui){
    switch(ui.panel){
      case $('#tabs-1')[0]: src = 'image1.jpg'; break;
      case $('#tabs-2')[0]: src = 'image2.jpg'; break;
      default: src = 'default.jpg';
    }
    $('#myimg').attr('src',src);
  }
});?????

In the future, I'd recommend adding more specifics to your question, and providing a more simplified example. Your page had numerous scripts on it, which makes it difficult to look at your specific situation.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...