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.
----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":""}','*'); } } });
----edit----
also make sure add ?enablejsapi=true
the iframe src, otherwise above javascript not work (source).
Comments
Post a Comment