I am new to jQuery, and I managed to create a tab interface. I want each section of my tab to have a YouTube video. However, when I click play on the video that is on tab 1 for example, and then switch to tab 2, the video on tab 1 still keeps on playing. Please see the entire code here:
I would greatly appreciate any help on how to stop the video once the user clicks on other tabs.
Also, when I run this on my Android, flash enabled phone, the videos don’t seem to play. Any idea of what I need to do to fix? Or do I need to fix anything else to make code browser compatible?
This should work:
http://jsfiddle.net/WwfFE/5/
I simply put all your URL’s in an array. When the user decides to leave the tab, I clear the
srcof theiframeso that the video “stops” playing.The first time your
currentTabvariable is still empty though, so I retrieve it by looking at which<li>has its class set toactive. From this<li>I take the link and set thecurrentTabvariable to itshref.When he gets back to any tab, you should not forget to set the
srcback though, else your iFrame will be empty. It’s what I do here:This code can still be optimized though to reduce the flickering. An easy way to do this is by setting a function on the
loadtrigger of theiframe‘s. This way you know when the video has been successfully set and it is then that you want to show the tab to the user.