在视频周围添加 html 会阻止 Vimeo api 工作

发布于 2025-01-04 05:21:08 字数 3387 浏览 0 评论 0原文

我在一个网站上有一个页面,并且块中有几个视频。当我播放一个视频然后点击关闭按钮或单击另一个框将其打开时,一切正常。但当我在视频周围添加额外的 html 标记时,问题就出现了,它破坏了关闭按钮的行为。

这是一个框的标记(我的页面中有多个框):

<div class="box" data-size="660,605">
    <div class="cunload2">
        <div class="expandable">
            <span class="simple">
                <a class="cunload" href="javascript:;"></a>
            </span>

            <div class="exandable-vids-container">
                <iframe ... ></iframe>
            </div>
        </div>
    </div>  
</div>

cunload 按钮是关闭框并卸载视频的按钮。

这是 javascript(如 vimeo api 页面 所示):

(function(){
    var vimeoPlayers = document.querySelectorAll('iframe'), player;

    for (var i = 0, length = vimeoPlayers.length; i < length; i++) {
        player = vimeoPlayers[i];
        $f(player).addEvent('ready', ready);
    }

    function addEvent(element, eventName, callback) {
        if (element.addEventListener) { element.addEventListener(eventName, callback, false); }
        else { element.attachEvent(eventName, callback, false); }
    }

    function ready(player_id) {
        var container = document.getElementById(player_id).parentNode.parentNode,
            froogaloop = $f(player_id),
            apiConsole = container.querySelector('.console .output');

        function setupSimpleButtons() {
            var unloadBtn = container.querySelector('.simple').querySelector('.cunload');
            addEvent(unloadBtn, 'click', function() { froogaloop.api('unload'); }, false);
        }

        setupSimpleButtons();
        $(".cunload, .box:not(.expanded)").click(function(){
             //if (!$(this).is('expanded')) {
                froogaloop.api('unload');
             //} 
        });
    }
})();

这工作得很好,但是当我在 iframe 周围添加额外的

(而且我确实需要)时,它不再起作用。

有什么线索吗?

编辑:问题更复杂,我在 iframe 周围添加了

  • 标签,如下所示:

<div class="box" data-size="660,605">
    <div class="cunload2">
        <div class="expandable">
            <span class="simple">
                <a class="cunload" href="javascript:;"></a>
            </span>

            <div class="exandable-vids-container">
                <ul>
                    <li><iframe ... ></iframe></li>
                    <li><iframe ... ></iframe></li>
                </ul>
            </div>
        </div>
    </div>  
</div>

并将 js 行修改

var container = document.getElementById(player_id).parentNode.parentNode

为:

var container = document.getElementById(player_id).parentNode.parentNode.parentNode.parentNode

我得到了它的工作。

问题是我使用

  • 标签来调用 jcarousel 并且它在我的 .exandable-vids-container
      之间添加了额外的 3 个 div。此外,有时我会调用这个轮播,有时不会,所以我真的不能在js中添加额外的 .parentNode 。这必须是动态的,我认为解决方案必须朝这个方向发展。

i got a page on a site and there are several videos within blocs. When i play one video and then hit the close button or click on another box to open it, it works all just fine. But the problem comes when i add extra html markup around the videos, it breaks the close button behavior.

Here's the markup of a box (i've got multiples in my page):

<div class="box" data-size="660,605">
    <div class="cunload2">
        <div class="expandable">
            <span class="simple">
                <a class="cunload" href="javascript:;"></a>
            </span>

            <div class="exandable-vids-container">
                <iframe ... ></iframe>
            </div>
        </div>
    </div>  
</div>

The cunload button is the one closing the box and unloading the video.

Here's the javascript (as seing at the vimeo api's page):

(function(){
    var vimeoPlayers = document.querySelectorAll('iframe'), player;

    for (var i = 0, length = vimeoPlayers.length; i < length; i++) {
        player = vimeoPlayers[i];
        $f(player).addEvent('ready', ready);
    }

    function addEvent(element, eventName, callback) {
        if (element.addEventListener) { element.addEventListener(eventName, callback, false); }
        else { element.attachEvent(eventName, callback, false); }
    }

    function ready(player_id) {
        var container = document.getElementById(player_id).parentNode.parentNode,
            froogaloop = $f(player_id),
            apiConsole = container.querySelector('.console .output');

        function setupSimpleButtons() {
            var unloadBtn = container.querySelector('.simple').querySelector('.cunload');
            addEvent(unloadBtn, 'click', function() { froogaloop.api('unload'); }, false);
        }

        setupSimpleButtons();
        $(".cunload, .box:not(.expanded)").click(function(){
             //if (!$(this).is('expanded')) {
                froogaloop.api('unload');
             //} 
        });
    }
})();

This works just fine, but when i add an extra <div> around the iframe (and i really need to) it doesnt work anymore.

Any clue?

EDIT: problem is more complicated, i added an <ul> and <li> tags around the iframes as such:

<div class="box" data-size="660,605">
    <div class="cunload2">
        <div class="expandable">
            <span class="simple">
                <a class="cunload" href="javascript:;"></a>
            </span>

            <div class="exandable-vids-container">
                <ul>
                    <li><iframe ... ></iframe></li>
                    <li><iframe ... ></iframe></li>
                </ul>
            </div>
        </div>
    </div>  
</div>

and modified the js line :

var container = document.getElementById(player_id).parentNode.parentNode

to:

var container = document.getElementById(player_id).parentNode.parentNode.parentNode.parentNode

and i got it working.

The problem is that i use the <ul> and <li> tags to call jcarousel and that it adds an extra 3 divs between my .exandable-vids-container and the <ul>. Moreover, sometimes i'll call this carousel and sometimes not, so i really can't go with adding extras .parentNode in the js. This would have to be dynamic and i think the solution has to be in that direction.

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文