简体   繁体   English

停止Vimeo嵌入Jquery Infinite Carousel中的上一个/下一个按钮

[英]Stop Vimeo embeds on previous / next buttons within Jquery Infinite Carousel

My setup: http://jsfiddle.net/ASa2K/1/ 我的设置: http//jsfiddle.net/ASa2K/1/

I have a Jquery Infinite Carousel which will have in it embedded Vimeo vids. 我有一个Jquery Infinite Carousel,里面装有Vimeo vids。

When 'Next' or 'Prev' is clicked, I would like it to stop all videos. 单击“下一步”或“上一页”时,我希望停止所有视频。 Currently it keeps playing the videos while clicking through. 目前,它一直在点击播放视频。

I've looked around but can't find much specific to my problem. 我环顾四周,但找不到我问题的具体内容。 I'm not so well-versed in js as you might have guessed! 你可能已经猜到了,我对js并不是那么精通!

Hej so first of you can find the api here Hej所以你们中的第一个人可以在这里找到api

http://vimeo.com/api/docs/player-js http://vimeo.com/api/docs/player-js

since its an iframe there is no back compatible way of communicating with it but there is something called postMessage that new browsers has. 因为它的iframe没有与它通信的后向兼容方式,但新浏览器有一些叫做postMessage的东西。 so You can write this. 所以你可以写这个。

$("iframe").each(function() {
  this.contentWindow.postMessage('{ "method": "pause" }', "http://player.vimeo.com");
});

the different methods are documented on the page. 页面上记录了不同的方法。 but this pauses all players. 但这会暂停所有玩家。

Here's a sample that should let you call from a button click: 这是一个示例,可让您通过单击按钮进行调用:

<script>
    function pauseAllVideos(){
        $("iframe").each(function() {
            this.contentWindow.postMessage('{ "method": "pause" }', "http://player.vimeo.com");
        });
    }
</script>

And this is the code from your html: 这是你的HTML代码:

<a href="#" onClick="pauseAllVideos(); return false;">PAUSE VIDEOS</a>

@megakorre's solution worked for me. @ megakorre的解决方案对我有用。 Simple and easy. 简单易行。

One caveat: If your domain is using https, it won't work unless you change http to https like this: 有一点需要注意:如果您的域名使用HTTPS,它不会,除非你改变HTTP像这样https使用:

this.contentWindow.postMessage('{ "method": "pause" }', "https://player.vimeo.com");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM