jQuery 如何在单击时停止 Vimeo 视频

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10401819/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 09:15:27  来源:igfitidea点击:

jQuery how to stop Vimeo video when click

jqueryjquery-pluginsvimeo

提问by test

here is the simple code: http://jsfiddle.net/YAFuW/1/

这是简单的代码:http: //jsfiddle.net/YAFuW/1/

basicly i tried to use like this:

基本上我试着这样使用:

<iframe src="http://player.vimeo.com/video/40977539?api=1" width="400" height="225" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>

<a href="#">STOP</a>

$('a').click(function() {
   alert('stoped');
   froogaloop.api('unload');
});

回答by Fresheyeball

I don't know a "good" or "right" way to accomplish this cross-browser.
Youtube's JavaScript API fails, too.

我不知道实现这种跨浏览器的“好”或“正确”方式。
Youtube 的 JavaScript API 也失败了。

But this method is reliable and does work.
Basically, it kills the <iframe>and rebuilds it.

但是这种方法是可靠的并且确实有效。
基本上,它会杀死<iframe>并重建它。

$('a').click(function() {
  alert('stoped');
  vimeoWrap = $('#vimeoWrap');
  vimeoWrap.html(vimeoWrap.html());
});

View at JSFiddle

在 JSFiddle 查看

回答by Anton Zimm

if you need only play or pause video use like this:

如果您只需要播放或暂停视频,请像这样使用:

var iframe = $('#vimeo-player')[0];
var player = $f(iframe);

$('#stop').click(function() {
    alert('stoped');
    player.api('pause');
});


$('#play').click(function(){
    alert('play');
    player.api('play');
})

and markup:

和标记:

<script src="http://a.vimeocdn.com/js/froogaloop2.min.js"></script>

<iframe id="vimeo-player" src="http://player.vimeo.com/video/40977539?api=1" width="400" height="225" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>
<a id="stop" href="#">STOP</a>
<a id="play" href="#">PLAY</a>

http://jsfiddle.net/zimm/8CV2S/14/

http://jsfiddle.net/zimm/8CV2S/14/

回答by JoanR

You missed get the id of the vimeo video:

您错过了获取 vimeo 视频的 ID:

var iframe = $('#vimeo-player')[0];
var player = $f(iframe);
player.api('unload');

Example: http://jsfiddle.net/joan_r/dutzh512/

示例:http: //jsfiddle.net/joan_r/dutzh512/

<html>
<head>
<script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<script src="http://a.vimeocdn.com/js/froogaloop2.min.js"></script>
<style>
#play,#pause,#stop{
    width:60px;
    margin:5px;
    text-align: center;
    border: solid;
    cursor:pointer;
}
</style>
</head>
<body>
<iframe id="vimeo-player" src="//player.vimeo.com/video/76979871" width="500" height="281" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
<div id="play">[PLAY]</div>
<div id="pause">[PAUSE]</div>
<div id="stop">[STOP]</div>
<script>
    $('#play').click(function() {
        var iframe = $('#vimeo-player')[0];
        var player = $f(iframe);
        player.api('play');
    });
    $('#pause').click(function() {
        var iframe = $('#vimeo-player')[0];
        var player = $f(iframe);
        player.api('pause');
    });
    $('#stop').click(function() {
        var iframe = $('#vimeo-player')[0];
        var player = $f(iframe);
        player.api('unload');
    });
</script>
</body>
</html>

回答by Roy Shoa

The best way is to work with Vimeo API:

最好的方法是使用Vimeo API

Example:

例子:

<script>
    var iframe = $('.vimeo-iframe').get(0);
    var player = new Vimeo.Player(iframe);
    player.pause();
    //player.play();
</script>

回答by deshg

If you use Vimeo's updated API code then you can do it like the following: http://jsfiddle.net/deshg/8CV2S/. You can see the stop button now gives you the alert and then the video is unloaded.

如果您使用 Vimeo 的更新 API 代码,那么您可以按照以下方式进行操作:http: //jsfiddle.net/deshg/8CV2S/。您可以看到停止按钮现在向您发出警报,然后视频被卸载。

Cheers!

干杯!