鼠标悬停时播放 vimeo 视频,鼠标移出时暂停

发布于 2024-12-15 04:53:31 字数 587 浏览 2 评论 0原文

我有一个页面,其中包含多个 vimeo 视频,以标准 iframe 方式嵌入。我在 HTML 头和 jquery (v 1.4.2) 中引用了 froogaloop.js (http://a.vimeocdn.com/js/froogaloop2.min.js)。我想要做的是能够在鼠标悬停时播放每个视频并在鼠标移出时暂停。

我在这里设置了一个 JSFiddle 页面: http://jsfiddle.net/g2Z2B/ 其中显示了我的内容我想做的 - 本质上只是将视频播放/暂停绑定到 jquery onmouseover/onmouseout 事件 - 但无论我读了多少 API 文档,我都无法让任何东西发挥作用。我尝试在这里拆开 API 演示页面: http://player.vimeo.com/playground但甚至无法让它在鼠标悬停时工作 - 而且每当我尝试删除不需要的东西时它也会破坏。我想做的只是一些非常简单的事情。

如果有人能在这里指出正确的方向,我将不胜感激!

I have a page which contains several vimeo videos, embedded in the standard iframe way. I have a reference to froogaloop.js (http://a.vimeocdn.com/js/froogaloop2.min.js) in the HTML head and also jquery (v 1.4.2). What I want to do is to be able to play each video onmouseover and pause onmouseout.

I've set up a JSFiddle page here: http://jsfiddle.net/g2Z2B/ which shows what I'm wanting to do - essentially just bind the video play/pause to the jquery onmouseover/onmouseout events - but no matter how much I read through the API documentation I just can't get anything to work. I've tried pulling apart the API demo page here: http://player.vimeo.com/playground but can't even get that to work on mouseover - plus whenever I try to strip out the unwanted stuff it breaks too. All I'm looking to do is something mega-simple.

If anyone could point me in the right direction here I'd be most grateful!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

数理化全能战士 2024-12-22 04:53:31

因此,第一件事是您应该使用 Froogaloop 的自定义 $f 选择器来抓取播放器。如果您查看 playground.html,这是在第 223 行完成的:

froogaloop = $f(player_id)

此外,您应该调用 .api('play') 而不仅仅是 ('play ')。完整的代码可能如下所示:

$(document).ready(function(){
    var player = $("#player_7256322");
        froogaloop = $f(player[0].id);

    player.mouseover(function(){
        froogaloop.api('play');
    }).mouseout(function(){
        froogaloop.api('pause');
    });
});

固定小提琴:

http://jsfiddle.net/g2Z2B/1/

So the first thing is that you should be grabbing the player with Froogaloop's custom $f selector. If you look at playground.html this is done on line 223:

froogaloop = $f(player_id)

Additionally, you should be calling .api('play') rather than just ('play'). Complete code might look something like this:

$(document).ready(function(){
    var player = $("#player_7256322");
        froogaloop = $f(player[0].id);

    player.mouseover(function(){
        froogaloop.api('play');
    }).mouseout(function(){
        froogaloop.api('pause');
    });
});

Fixed fiddle:

http://jsfiddle.net/g2Z2B/1/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文