javascript - BXSlider Pause Youtube Video When Switching Slides -


i have following example of bxslider, have 4 slides each having youtube video. problem when play video , go next slide, keeps on playing:

http://jsfiddle.net/isherwood/xwl9y/

$(document).ready(function () { $('.bxslider').bxslider(); }); 

can out make youtube video pause when going next slide?

var slider = $("#gallery").bxslider({     adaptiveheight:true,     auto:true,      autostart:true,      autocontrols:true,      video:true,     onslideafter: function(slide){        if (slide.find("iframe:first").length) {            slider.stopauto();        }     } }); 

you might able use slide.find("div.fluid-width-video-wrapper:first") if use iframes other things in in slider.

source

----update----

var slider = $('.bxslider').bxslider({   onslideafter: function(slide, oldindex, currentslide){     oldslide = $( '.bxslider > li:nth-child(' + (oldindex+1) + ')');       youtubevideo = oldslide.find('iframe[src*=youtube]');       if ( youtubevideo.length ) {         youtubevideo.get(0).contentwindow.postmessage('{"event":"command","func":"pausevideo","args":""}','*');       }   } }); 

source

----edit----

also make sure add ?enablejsapi=true the iframe src, otherwise above javascript not work (source).


Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -