hide() 可以正常工作,但 fadeOut() 不能正常工作?

发布于 2025-01-07 06:03:08 字数 969 浏览 6 评论 0 原文

我有一个带有保持帧和视频的 jquery 幻灯片。单击保持帧时,我希望它淡出并且视频淡入并播放。

它适用于 show() 和 hide(),但是当我将其更改为 fadeIn() 和 fadeOut() 时,整个事情就会崩溃。

知道为什么会发生这种情况吗?

          $('.holdFrame1').click(function(){  
            $(".holdFrame1").delay(500).hide();         
            $(".hiddenVideo1").show(
            function(){          
               $f(players[0]).api('play');                                                                                                                     
});

这就是我想要完成的任务,

          $('.holdFrame1').click(function(){  
            $(".holdFrame1").delay(500).fadeOut('slow');         
            $(".hiddenVideo1").show(
             function(){          
               $f(players[0]).api('play');                                                                                                                     
       });
      });

但这会导致图像不会淡出,而是留在原处,而隐藏的视频出现在其下方。

I have a jquery slideshow with hold frames and videos. When the hold frame is clicked, I want it to fade out and the video to fade in and play.

It works with show() and hide(), but when I change it to fadeIn() and fadeOut() the whole thing breaks.

Any idea why this is happening?

          $('.holdFrame1').click(function(){  
            $(".holdFrame1").delay(500).hide();         
            $(".hiddenVideo1").show(
            function(){          
               $f(players[0]).api('play');                                                                                                                     
});

This is what I would like to accomplish

          $('.holdFrame1').click(function(){  
            $(".holdFrame1").delay(500).fadeOut('slow');         
            $(".hiddenVideo1").show(
             function(){          
               $f(players[0]).api('play');                                                                                                                     
       });
      });

But that causes the image not to fadeOut, but rather stay in place while the hidden video appears below it.

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

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

发布评论

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

评论(3

掌心的温暖 2025-01-14 06:03:08

您需要使用 .fadeOut() (和 .fadeIn()) 正确使用回调。因此,您正在寻找的方法签名是:

.fadeOut( [duration] [, callback] )

我必须预测您的标记是什么样子,但一般来说这并不太困难。使用:

.videoContainer {
    background: grey;
    height: 400px;
    width: 560px;
    padding: 10px;
}
.holdFrame,
.hiddenVideo {
    width: 100%;
    height: 100%;
}
.holdFrame {
    background: green;
}
.hiddenVideo {
    background: yellow;
    display: none;
}

<div class="videoContainer">
    <div class="holdFrame">Click to play video.</div>
    <div class="hiddenVideo">Video will be here.</div>
</div>

您可以:

$(".holdFrame").click(function(){
    var $this = $(this);

    $this.fadeOut(500, function(){
        $this.siblings('.hiddenVideo').fadeIn(500, function (){
            $f(players[0]).api('play');
        });
    });
});

http://jsfiddle.net/yeRxP/

这样做的好处(其中我我相当确定我在不知情的情况下修改了您的标记和 CSS),您可以在同一页面上拥有多个视频播放器,并且它们不会发生冲突:

http://jsfiddle.net/yeRxP/2/

由于我不熟悉您的视频播放器,您必须修改它才能在 上播放正确的视频.fadeIn() 回调。

You need to use .fadeOut() (and .fadeIn()) correctly with callbacks. So the method signature you're looking for is:

.fadeOut( [duration] [, callback] )

I have to predict what your markup looks like, but in general this isn't too difficult. Using:

.videoContainer {
    background: grey;
    height: 400px;
    width: 560px;
    padding: 10px;
}
.holdFrame,
.hiddenVideo {
    width: 100%;
    height: 100%;
}
.holdFrame {
    background: green;
}
.hiddenVideo {
    background: yellow;
    display: none;
}

<div class="videoContainer">
    <div class="holdFrame">Click to play video.</div>
    <div class="hiddenVideo">Video will be here.</div>
</div>

You can:

$(".holdFrame").click(function(){
    var $this = $(this);

    $this.fadeOut(500, function(){
        $this.siblings('.hiddenVideo').fadeIn(500, function (){
            $f(players[0]).api('play');
        });
    });
});

http://jsfiddle.net/yeRxP/

The nice thing about this (in which I'm fairly certain I've modified your markup and CSS without knowing it), you can have more than one video player on the same page and they won't conflict:

http://jsfiddle.net/yeRxP/2/

Since I'm not familiar with your video player, you'll have to modify it to play the correct video on the .fadeIn() callback.

萌辣 2025-01-14 06:03:08

如果您想用 fadeIn() 替换 show() 并使用回调,您需要使用与 fadeIn() 关联的速度:

$('.holdFrame1').click(function(){   
    $(".holdFrame1").fadeOut('slow');          
    $(".hiddenVideo1").fadeIn('slow', function(){
        $f(players[0]).api('play');
    });
}); 

有关更多信息: http://api.jquery.com/fadeIn/

If you want to replace show() with fadeIn() and use a call back you need to use a speed associated with the fadeIn():

$('.holdFrame1').click(function(){   
    $(".holdFrame1").fadeOut('slow');          
    $(".hiddenVideo1").fadeIn('slow', function(){
        $f(players[0]).api('play');
    });
}); 

For more information: http://api.jquery.com/fadeIn/

挽梦忆笙歌 2025-01-14 06:03:08

http://jsfiddle.net/pA58v/

<button class="holdFrame1">test</button>

<video class="hiddenVideo1" style="border:1px solid #000"></video>​


$(document).ready(function() {

$(".hiddenVideo1").hide();  

$('.holdFrame1').click(function(){  
        $(".holdFrame1").delay(500).hide();         
        $(".hiddenVideo1").show();       
         $f(players[0]).api('play');              
      });


});

http://jsfiddle.net/pA58v/

<button class="holdFrame1">test</button>

<video class="hiddenVideo1" style="border:1px solid #000"></video>​


$(document).ready(function() {

$(".hiddenVideo1").hide();  

$('.holdFrame1').click(function(){  
        $(".holdFrame1").delay(500).hide();         
        $(".hiddenVideo1").show();       
         $f(players[0]).api('play');              
      });


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