jqueryjsonapivimeofroogaloop

Pause Vimeo universal embed when hidden using jQuery


I have a Vimeo video (via universal embed iframe) hidden on my page. Clicking a link fades it in, and clicking outside of the video (lightbox-style) fades it out and hides it - but the video keeps playing. I read on Vimeo's API that you can use JSON objects to pause the video, but I don't understand what they're saying.

HTML:

<img id="show_tide" class="vid" src"#">
<i<iframe id="tide" class="vim" src="http://player.vimeo.com/video/1747304?portrait=0&amp;color=ffffffapi=1" width="726" height="409" frameborder="0"></iframe>

JavaScript:

$('#underlay').click(function() {
    //pause VISIBLE (there are multiple) Vimeo video via API
    $('.vim, #underlay').fadeOut(400);
});

Solution

  • You need to add from one of the froogaloop libraries.

    JS

    player=$f(document.getElementById('tide'));// you can use jquery too: $('#tide')[0] 
    player.api('pause');
    

    Annoyingly simple. Here's an example on jsfiddle.net.