简体   繁体   English

jQuery:如何向下滑动一个绝对div以及另一个向下滑动的div?

[英]jQuery: How to slide down an absolute div along with another div that is sliding down?

I have a text container that is absolutely positioned on the bottom of the page and above it, there is a Show/Hide button (which is also absolutely positioned). 我有一个文本容器,它绝对位于页面底部,而在页面上方,有一个“显示/隐藏”按钮(也绝对位于其中)。

I need to slide the Show/Hide button up and down along with the text container when it slide toggles. 滑动切换时,我需要上下滑动“显示/隐藏”按钮以及文本容器。 When the text container slides down, the button must follow it and remain visible at the bottom of the page. 当文本容器向下滑动时,该按钮必须紧随其后,并在页面底部保持可见。 When the text container slides up, the button must slide up with it. 文本容器向上滑动时,按钮必须随之向上滑动。 I can't seem to get this to work. 我似乎无法使它正常工作。

HTML: HTML:

<div class="wrapper">
  <div class="button">
     <span>Hide</span><span style="display:none;">Show</span></div>
  <div class="container">Lorem ipsum dolor sit amet....</div>
</div>

jQuery: jQuery的:

$(".button").click(function () {
  $(this).find("span").toggle();
  $(".container").slideToggle("slow");
});

Here is the fiddle: http://jsfiddle.net/UDe8r/1/ 这是小提琴: http : //jsfiddle.net/UDe8r/1/

Check here DEMO http://jsfiddle.net/yeyene/fpPJz/3/ 在这里检查演示http://jsfiddle.net/yeyene/fpPJz/3/

JQUERY JQUERY

$(document).ready(function(){
    $('.wrapper a').on('click',function(){
        if($(this).text() == 'Show')
            $(this).text('Hide');
        else
            $(this).text('Show');         
        $('.wrapper .content').slideToggle('slow');
    });
});

CSS CSS

.wrapper {
    height: 400px;    
    position: relative;
}
.wrapper #button{
    cursor:pointer;
    position: relative;
    left:0;
    top:0;
    padding:0;
}
.wrapper #button a{
    padding:0 5px;
    text-align:right;
    background:green;
    cursor:pointer;
}
.container{    
    position: absolute;
    bottom:0;
}
.content{
    display:none;
    padding: 10px;
    background-color: #bbb;
}

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

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