问题是它突然打开,但在相反的方向上它应该正常工作。
$('.test').click(function() {
var test = $(this).prev();
if (test.innerHeight() == 106) {
test.animate({
height: "100%",
}, 1000);
} else {
test.animate({
height: 106,
}, 1000);
}
});
p {
background-color: #E3DEDE;
height: 106px;
overflow: hidden;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.1/jquery.min.js"></script>
<p>The best products begin with the best ingredients. Flour is milled only from select grades of the best wheat grains; the best nature has to offer, it looks like white powder. We have many varieties and formats for diverse applications.High quality grade.
This sort of flour is pretty clear from which is preparing only from well-peeled grains. This grade of flour characterize by a low content of gluten and large amount of starch. This grade of flour has white color with a light milky shade. This grade
often use in cooking, because batch turns out splendid and porous.The first grade of flout. This is the most popular grade, which allows for a small number of grain shells. This grade of flour is characterize large amount of gluten, which makes it possible
to get a very elastic dough. This grade of flour has a light yellow color. Batches turns out volumetric and fragrant.The second grade of flour. This grate is characterized by a darker grayish color, which has a large number of grain envelopes this is
allowing in the composition. Batches turns out lush and porous. This grade of flour don’t use for turn out for saltwater fish splashDifferent grade of flour differ from each other parameters: the amount of flour, which turn our from 100 kg of grain,
product color, ash content, particle size, as well as the presence of bran and the amount of gluten.</p>
<button class="test">test</button>
如何出行?您需要单击以将块打开到最大高度。我觉得问题就出在这里。
height: "100%"
我试着把 auto 放在这里,它不起作用。只需要一个整数值。
jsfiddle示例
您可以使用scrollHeight 来计算块的实际高度。然后在参数中代入这个值
height至于在其他块的“顶部”打开的可能性,在我看来,这应该由布局决定。例如,看一下position属性