jquery 展开/切换 - 初始 div 大小
请参阅下面的代码...
我很困惑,想最初显示下面 div 的 30px(高度)。目前我只能切换显示或隐藏。
我真正想要的是显示前 30px 并切换/显示下面包含的任何内容。
<html>
<head>
<script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<meta charset=utf-8 />
<script type="text/javascript">
$(document).ready(function() {
// Hide the "view" div.
$('div.view').hide();
// Watch for clicks on the "slide" link.
$('div.slide').click(function() {
// When clicked, toggle the "view" div.
$('div.view').slideToggle(400);
return false;
});
});
</script>
</head>
<body>
<div class="view">
<p>shown/hidden depending on the toggle above. </p>
<p>shown/hidden depending on the toggle above. </p>
<p>shown/hidden depending on the toggle above. </p>
<p>shown/hidden depending on the toggle above. </p>
<p>shown/hidden depending on the toggle above. </p>
<p>shown/hidden depending on the toggle above. </p>
<p>shown/hidden depending on the toggle above. </p>
<p>shown/hidden depending on the toggle above. </p>
<p>shown/hidden depending on the toggle above. </p>
</div>
<div class="slide" style="cursor: pointer;">Show/Hide</div>
</body>
</html>
谢谢
Please see my code below...
I am puzzled and want to initially show 30px (in height) of the below div. At present I can only toggle to show or hide.
What I actually want is to show the first 30px and toggle/show anything contained below that.
<html>
<head>
<script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<meta charset=utf-8 />
<script type="text/javascript">
$(document).ready(function() {
// Hide the "view" div.
$('div.view').hide();
// Watch for clicks on the "slide" link.
$('div.slide').click(function() {
// When clicked, toggle the "view" div.
$('div.view').slideToggle(400);
return false;
});
});
</script>
</head>
<body>
<div class="view">
<p>shown/hidden depending on the toggle above. </p>
<p>shown/hidden depending on the toggle above. </p>
<p>shown/hidden depending on the toggle above. </p>
<p>shown/hidden depending on the toggle above. </p>
<p>shown/hidden depending on the toggle above. </p>
<p>shown/hidden depending on the toggle above. </p>
<p>shown/hidden depending on the toggle above. </p>
<p>shown/hidden depending on the toggle above. </p>
<p>shown/hidden depending on the toggle above. </p>
</div>
<div class="slide" style="cursor: pointer;">Show/Hide</div>
</body>
</html>
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
尝试
添加此 css
JS
演示
Try this
Add this css
JS
Demo
好的,所以我要做的就是将内容设置为溢出:隐藏,然后动态更改切换框的高度。如果溢出设置为隐藏,那么任何超出框的宽度/高度的内容都会......好吧,它将被隐藏。
所以你会做这样的事情:
HTML...
在 JS...
无论如何,类似的事情。尚未测试该代码,但这是基本思想。
希望有帮助。祝你好运 :)
OK, so what I would do is set the content to overflow:hidden, and then just dynamically change the height of the box on the toggle. If overflow is set to hidden, then anything that falls outside the width/height of the box will... well, it will be hidden.
So you would do something like this:
The HTML...
And in the JS...
Something like that, anyway. Haven't tested that code, but that's the basic idea.
Hope that helps. Good luck :)
CSS:
HTML:
Jquery:
小提琴:http://jsfiddle.net/Vknqw/
CSS:
HTML:
Jquery:
fiddle : http://jsfiddle.net/Vknqw/
你是这个意思吗?
http://jsfiddle.net/eiu165/ew5dH/
is this what you mean ?
http://jsfiddle.net/eiu165/ew5dH/
如果我理解你想要做什么,那么你真正需要的是将你的高度设置为
auto
。然而,这是不可能的。我想出了这个来模拟:http://jsfiddle.net/txKt7/1/
< em>注意:这只是一个概念证明,并未使用您实际的 html 标记。需要稍微调整以适应您的具体情况。
If I'm understanding what you're trying to do, what you really need is to animate your height to
auto
. However, this isn't possible. I came up with this to simulate that:http://jsfiddle.net/txKt7/1/
NOTE: This is just a proof of concept which is not using your actual html markup. It would need to be adjusted slightly to fit your exact situation.
像这样的东西应该足够了:
Something like this should suffice: