简体   繁体   English

将div滑入和滑出视口

[英]Slide div in and out of viewport

I'm trying to achieve an effect similar to airbnb.com's home page and the how it works button. 我正在尝试实现类似于airbnb.com主页以及按钮工作方式的效果。

I've been able to do the following fiddle: http://jsfiddle.net/n89z4bz3/ 我已经能够进行以下操作: http : //jsfiddle.net/n89z4bz3/

However, I'm unable to achieve the slide effect as well as fixing the visible container to the bottom of the slid in upper-container . 但是,我无法实现滑动效果,也无法将可见容器固定到upper-container滑动的底部。

My Jquery code is here: 我的Jquery代码在这里:

$(document).ready(function(){
    var heightVar = 0 - $(window).height();
    $('.upper-container').css('top',heightVar+'px');
    $('.main-container').css('height', $(window).height()+'px');
    $('.click-this').on('click', function(){
        $('.upper-container').css('top', '0');
        $('.main-container').css('margin-top',$('.upper-container').height()+'px');
    });
});

My HTML is setup as follows: 我的HTML设置如下:

<div class="upper-container">
    Hidden container
</div>
<div class="main-container">
    Visibile container
    <div class="click-this">
        Click This to Slide Down
    </div>
</div>

Try this 尝试这个

http://jsfiddle.net/n89z4bz3/1/ http://jsfiddle.net/n89z4bz3/1/

 $(document).ready(function() { var heightVar = 0 - $(window).height(); $('.main-container').css('height', $(window).height() + 'px'); $('.click-this').on('click', function() { $('.upper-container').animate({ height: '100px', paddingTop: '40px' }, 500); }); }); 
 .upper-container { position: reltive; width: 100%; padding-top: 0px; background: red; height: 0px; overflow: hidden; } .main-container { background: blue; position: relative; } .click-this { background: #fff; color: #333; padding: 20px; margin-left: 20px; width: 300px; margin-top: 40px; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> <div class="upper-container"> Hidden container </div> <div class="main-container"> Visibile container <div class="click-this"> Click This to Slide Down </div> </div> 

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

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