Reputation: 543
So i'm trying to switch some small youtube thumbnail still images so onclick they load the relevant youtube video in main video at top. I've pretty much got it working great. But on switch of video i'd like them to start autoplaying.
Here's a JSFiddle what i got so far: http://jsfiddle.net/jw1sw01v/4/
jQuery:
$(document).on('click', '.ph-video', function (event) {
var change = $(this).find("img").attr("src").split("/");
$(".ph-master-video-section > iframe").attr("src","https://www.youtube.com/embed/" + change[4]);
});
If you click on the thumbs you'll see it's switching perfect. Just like it to auto play on switch.
Any ideas much appreciated?
Upvotes: 1
Views: 1620
Reputation: 449
you need to add to iframe src : ?rel=&autoplay=1
$(document).on('click', '.ph-video', function (event) {
var change = $(this).find("img").attr("src").split("/");
$(".ph-master-video-section > iframe").attr("src", "https://www.youtube.com/embed/" + change[4]+"?rel=&autoplay=1");
});
check this JSFiddle
Upvotes: 4