首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >jQuery停止视频脚本

jQuery停止视频脚本
EN

Stack Overflow用户
提问于 2012-02-02 06:18:13
回答 2查看 1.6K关注 0票数 0

这个脚本工作得很好,但是如果启动了一个新视频,它所做的就是停止一个正在播放的视频的实例。当调用函数stopAllButMe();时,我如何重写它来停止播放视频的所有实例?

代码语言:javascript
复制
function stopAllButMe(playerState, player) {
    if (playerState=='PLAYING') {
        var myId = player.getId();
        projekktor('*').each(function() {
            if (this.getId()!==myId) {
                this.setStop();
            }
        });
    }
}

projekktor('*').each(function() {
    this.addListener('state', stopAllButMe);
});
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-02-02 06:21:56

代码语言:javascript
复制
function stopAllButMe(playerState) {
  if (playerState=='PLAYING') {
    projekktor('*').each(function() {

      this.setStop();

    });
  }
}
projekktor('*').each(function() {
  this.addListener('state', stopAllButMe);
});

“if”语句正在根据输入进行检查。

票数 0
EN

Stack Overflow用户

发布于 2012-02-02 06:22:38

代码语言:javascript
复制
function stopAllButMe (state, player) {

    //iterate through each of the `<video>` elements
    $.each($('video'), function () {

        //check if the current iteration is the same element that got passed into this function
        if (this.id != player.id) {

            //stop any `<video>` element that isn't the one passed into this function
            this.stop();
        }
    });
}

//find each `<video>` element and add an event handler for the `state` event
$('video').bind('state', stopAllButMe);

这里假设每个<video>标记都有自己的惟一ID。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9104205

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档