简体   繁体   English

项目淡入后,jQuery向下滑动div

[英]Jquery slide down div after an item fades in

this is my jquery code 这是我的jQuery代码

        jQuery(document).ready(function(){  
            jQuery('.start_video').click(function(){
                jQuery(this).fadeOut("slow", function(){
                    jQuery('#video').animate({ opacity: 'show' }, "slow");
                    jQuery('#video_stream').animate({slideDown: 'slow' }, "slow");
                });
            });

            jQuery('.close_video').click(function(){
                jQuery('#video').fadeOut("slow", function(){
                    jQuery('.start_video').fadeIn("slow");
                });
            });
        });   

Here is my html code 这是我的HTML代码

<div id="video_stream">
    <a href="#" class="start_video">Start Video</a>

    <div id="video" class="hidden">
        <a href="#" title="#" class="close_video">Close</a> 
    </div>
</div>
</div>

I have some standard CSS. 我有一些标准的CSS。 When the start_video link is clicked, the start_video link fades out and after that, the video div fades in. Inside the video div is a close_video link. 单击start_video链接后,start_video链接会淡出,此后,视频div会淡入。video div内是close_video链接。 When that link is clicked, the video div fades out and the start_video link fades in. However, I want to also have the "video_stream" div that wraps everything to slide down as its height changes with the fading in of "video" and also slideUp when the height changes with the fadeOut of "video". 单击该链接后,视频div逐渐淡出,start_video链接也逐渐淡入。但是,我还想拥有一个“ video_stream” div,该组件可以随着高度随着“视频”的淡入而变化,从而将所有内容向下滑动当高度随着“视频”的淡出而变化时,为slideUp。

I was wondering how to do this. 我想知道如何做到这一点。 I tried adding in slideUp functions in Jquery but I think I was putting them in the wrong place. 我尝试在Jquery中添加slideUp函数,但我认为我将它们放在错误的位置。 I also tried the .animate() function using the slideUps but that did not work. 我也尝试了使用slideUps的.animate()函数,但是没有用。 I want it to be a smooth slideDown while the "Video" div is fading in and vice versa. 我希望在“视频” div逐渐消失时,它能够顺畅地滑动,反之亦然。

Thanks in advance! 提前致谢!

slideDown() is actually just a way to show() by sliding down, so you don't want to call it on #video_stream since it should always be visible. slideDown()实际上只是向下滑动show()的一种方式,因此您不希望在#video_stream上调用它,因为它应该始终可见。

Also, fading in does not cause something to gradually grow in height; 此外,淡入并不会导致某些东西的高度逐渐增加; the size is allocated all at once and then it fades in. 大小会立即分配,然后逐渐消失。

If you want the bottom of #video_stream to slide as #video fades in and out, you'll have to have something inside of it sliding up and down to gradually change the height of #video_stream . 如果您希望#video_stream底部随着#video淡入淡出而滑动,则必须在其中上下滑动以逐渐改变 #video_stream 的高度

The simplest way to accomplish this is to forget about fading and use sliding to hide and show everything: 完成此操作的最简单方法是忘记淡入淡出并使用滑动来隐藏和显示所有内容:

 jQuery(document).ready(function(){  
        jQuery('.start_video').click(function(){
            jQuery(this).slideUp("slow", function(){
                jQuery('#video').slideDown("slow");
            });
        });

        jQuery('.close_video').click(function(){
            jQuery('#video').slideUp("slow", function(){
                jQuery('.start_video').slideDown("slow");
            });
        });
 });

This may not be exactly what you're looking for, but it should be a start. 这可能不完全是您要找的东西,但这应该是一个开始。

You may also want to use unique ids on your links instead of classes , since this jQuery script will act on all elements with class start_video and close_video , if there are multiple. 您可能还想在链接而不是上使用唯一的ID ,因为如果有多个jQuery脚本将对类start_videoclose_video所有元素close_video

Thanks for the response!. 感谢您的回复! I ended up using the jquery UI library and using the standard .show and .hide methods. 我最终使用了jQuery UI库,并使用了标准的.show和.hide方法。 I used the "bind" type for the effect. 我为效果使用了“绑定”类型。 It worked out well for me. 对我来说效果很好。 The code remained almost the same as the original I had. 代码几乎与原始代码相同。

<script type="text/javascript" src="js/jquery-ui-1.7.2.custom.min.js"></script>
    <script type="text/javascript">
        jQuery.noConflict();
    </script>

      <script type="text/javascript">
        jQuery(document).ready(function(){  
            jQuery('#start_video').click(function(){
                jQuery(this).fadeOut("slow", function(){
                    jQuery('#video').show("blind", 500);

                });
            });

            jQuery('#close_video').click(function(){
                jQuery('#video').hide( "blind", 500, function(){
                    jQuery('.start_video').fadeIn("slow");
                });
            });
        });   
    </script> 

HTML Code HTML代码

<div id="wrapper">

<div id="video_stream">
    <a href="#" title="launch video stream" id="start_video"><img src="images/video_start.png" width="800" height="56" alt="launch video stream (800x600)" border="0"/></a>

    <div id="video" class="hidden">
        <a href="#" title="close the video" id="close_video"><img src="images/video_close.png" width="44" height="44" alt="close the video" border="0" /></a> 
    </div>
</div>
</div>

This should work out for anybody looking to do this. 这应该为任何希望这样做的人解决。 The no conflict is in there because I added this code to my wordpress installation which had some prototype running as well. 那里没有冲突,因为我将此代码添加到了同时运行一些原型的wordpress安装中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM