$(".div3Btn").click(function() {
$(".div2").show("slide", {
direction: "up"
}, 5000);
});
.div1 {
display: flex;
height: 100%;
flex-direction: column;
background-color: #919191;
}
.div2 {
display: flex;
overflow-y: auto;
flex: 1;
height: 500px;
background-color: #a8d810;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="div1">
<div class="div2" style="display: none;">hjghjgjghj</div>
<div class="div3">
<button class="div3Btn">Click me!</button>
</div>
</div>
关于在时间和方向上使用show()
/ hide()
函数,我有一个问题。如上面的代码段所示,如果单击该按钮,它将立即跳转到底部,但不会跟随div1向下滑动。那么如果我想使用该功能,我该如何解决呢?
$(".div3Btn").click(function() {
$(".div2").slideToggle(5000);
});
.div1 {
display: flex;
height: 100%;
flex-direction: column;
background-color: #919191;
}
.div2 {
display: flex;
overflow-y: auto;
flex: 1;
height: 500px;
background-color: #a8d810;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="div1">
<div class="div2" style="display: none;">hjghjgjghj</div>
<div class="div3">
<button class="div3Btn">Click me!</button>
</div>
</div>
(问题与使用Firefox运行链接功能非常相似)
向下滑动的另一个问题是当我使用flex: 1
进行某些div时,然后使用slideToggle()
函数,它没有任何向下滑动或向上动画的div。如果我必须使用flex: 1
为divs如何解决?
我认为你已经格式化了.show()
函数错误。试试.show( duration [, easing ] [, complete ] )
$(".div3Btn").click(function() {
$(".div2").show(5000, "swing", function() {
// Animation complete.
});
});
.div1 {
display: flex;
height: 100%;
flex-direction: column;
background-color: #919191;
}
.div2 {
display: flex;
overflow-y: auto;
flex: 1;
height: 500px;
background-color: #a8d810;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="div1">
<div id="div2" class="div2" style="display: none;">hjghjgjghj</div>
<div class="div3">
<button id="div3Btn" class="div3Btn">Click me!</button>
</div>
</div>