【问题标题】:jQuery replace Vimeo embed with fade in and fade outjQuery用淡入淡出替换Vimeo嵌入
【发布时间】:2011-04-16 05:30:49
【问题描述】:

我想淡出 Vimeo 通用嵌入(iframe 版本),暂停它,淡入另一个,然后自动播放。我的代码淡出并暂停第一个视频,但立即引入新的(没有淡入淡出),然后不自动播放。我猜这是语法问题。我正在使用 froogaloop js 库来控制 Vimeo API。

想法?感谢您的帮助!

HTML:

    <div id="fire" class="vim">
        <iframe id="regular" class="vid" src="http://player.vimeo.com/video/22327264?api=1&amp;title=0&amp;byline=0&amp;portrait=0&amp;color=ffffff"></iframe>
        <iframe id="behind" class="vid" src="http://player.vimeo.com/video/22466069?api=1&amp;title=0&amp;byline=0&amp;portrait=0&amp;color=ffffff"></iframe>
        <p style="float:left">
            "Sound of Fire"<br />
            This Century<br />
            Warner Brothers Records
        </p>
        <p id="bts" style="float:right;color:#000000;cursor:pointer;">
            &nbsp;<br />
            Click to launch the "Sound of Fire" behind the scenes video!<br />
            &nbsp;
        </p>
    </div>

JavaScript:

    $('#behind').hide();
    $('#bts').click(function() {
        $('#regular').fadeOut(400);
        var player=$f($('.vid:visible')[0]);
        player.api('pause');
        $('#behind').fadeIn(400);
        player.api('play');
    });

【问题讨论】:

    标签: jquery api fadein fadeout vimeo


    【解决方案1】:

    jQuery 的.fadeIn().fadeOut() 在动画运行时不会阻止进一步的代码执行。如您所见,这意味着播放器在淡出开始时立即暂停,然后立即开始淡入,并且播放器取消暂停。

    如果要在动画完成时使用执行代码,则需要使用(可选)回调参数:

    $('#bts').click(function() {
        $('#regular').fadeOut(400, function () {
            $f(this).api('pause');
            $('#behind').fadeIn(400, function () {
                $f(this).api('play');
            });
        });
    });
    

    【讨论】:

    • @Matt Ball- 太好了,淡出/淡入现在完美运行。但是,Vimeo API 暂停/播放不起作用。有什么想法吗?
    • @techno:刚刚编辑。这是一个猜测,但我认为这是正确的猜测;-)
    • @Matt 暂停 #regular,不会在后面重播。我不能用 ID 打电话给他们吗?
    • @techno:哦,哎呀!抱歉,我的代码两次都调用.api('pause') - 绝对是一个错字!固定的。当this 已经是对正确元素的引用时,无需按 ID 重新选择。而且,来吧,这是编写代码的借口,您可以将其读为“F this”
    • @Matt 我也没有注意到.. 一定迟到了:D!美丽的答案,谢谢你的帮助。我可以为另一件事挑选你的大脑吗?我有一个名为#close 的div,它会淡出#fire 及其所有内容。当 div 关闭时,您是否有重置 #regular 和 #behind 的建议?我在这里提出了这个问题:stackoverflow.com/questions/5684902/…
    【解决方案2】:

    你已经定义了

    var player=$f($('.vid:visible')[0]);
    

    并使用相同的 var player 进行操作(暂停和播放

    player.api('pause')player.api('play)`

    顺便说一句,你用这段代码做了什么

    var player=$f($('.vid:visible')[0]);
    

    更新

    我希望这会起作用(原始代码)

    $('#behind').hide();
    $('#bts').live('click',function() {
        $('#regular').fadeOut(400,function(){
            $f(this).api('pause');
        });
        $('#behind:hidden').fadeIn(400,function(){
            $f(this).api('play');
        });      
    })
    

    注意:感谢@Matt Ball

    【讨论】:

    • @diEcho var player=$f($('.vid:visible')[0]);定义可见视频。
    • visible video 表示你想暂停iframe with id=regular m i 的视频,对吗??
    • @diEcho 更新的代码不起作用。 #regular 淡出但继续播放。 #behind 永远不会消失。
    • 为什么是'iframe#regular' 而不是'#regular'?最多可以有 1 个具有任何特定 ID 的元素,因此没有理由进一步指定。
    • 不,实际上,jQuery 选择器通过从右到左过滤来工作(有一个例外)。 forum.jquery.com/topic/about-selectors-right-to-left
    猜你喜欢
    • 1970-01-01
    • 2018-03-02
    • 1970-01-01
    • 2013-02-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多