admin管理员组文章数量:1399901
I'm creating sidebars including tables for a website.
I would like:
- only five rows to show at first
- by clicking a link in at the bottom of the sidebar 15 rows will be shown and the link text will change.
- by clicking the link again when the div is fully open the sidebar only shows the first five again and the link text changes back to the first one again.
So I'm looking for some kind of toggle div function to do this for me, but I want a part of the div to be always visible.
Here is a screenshot of my sidebars:
Is there anyone who have a good solution to my problem?
I'm creating sidebars including tables for a website.
I would like:
- only five rows to show at first
- by clicking a link in at the bottom of the sidebar 15 rows will be shown and the link text will change.
- by clicking the link again when the div is fully open the sidebar only shows the first five again and the link text changes back to the first one again.
So I'm looking for some kind of toggle div function to do this for me, but I want a part of the div to be always visible.
Here is a screenshot of my sidebars: http://cl.ly/image/390J2u2z1W1Z
Is there anyone who have a good solution to my problem?
Share Improve this question edited Nov 26, 2012 at 14:59 DrMtotheac asked Nov 26, 2012 at 14:11 DrMtotheacDrMtotheac 1273 silver badges8 bronze badges 2- @Caribou Well we were quite helpful anyway... See below... – jtheman Commented Nov 26, 2012 at 14:38
- @jtheman lol - I should have looked I need a break I think :) – Caribou Commented Nov 26, 2012 at 14:39
4 Answers
Reset to default 5It all depends on what is really your content, but simpliest would be to alter div
height to match your requirements or use two div
s (one for "shortened" version, other for "full" and show/hide them accordingly.
Separate your main <div>
into multiple, smaller <div>
s... then just hide the entirety of your internal <div>
s. With jQuery's .toggle
or .hide
/.show
functions.
Just check this demo
JS:
$('.js_toggle').on('click', function(event) {
$('table').toggleClass('full-table');
event.preventDefault();
});
HTML:
<table>
<tr>
<td>tr01</td>
<td>tr02</td>
</tr>
…
<tr>
<td>tr01</td>
<td>tr02</td>
</tr>
</table>
<a href="#" class="js_toggle">toggle_table</a>
CSS:
table tr:nth-child(n+6) {
display: none;
}
table.full-table tr {
display: block;
}
Add a class to the rows you dont want to show first
<tr class="toggle"> ..... </tr>
CSS:
tr.toggle { display: none; }
Sidebar link:
<a href="#" id="toggle">Toggle</a>
then use jQuery toggle() to toggle on and off
<script>
$(function(){
$('a#toggle').click(function(e)
{
e.preventDefault();
$('tr.toggle').toggle();
});
});
</script>
本文标签: javascriptCan I showhide part of divStack Overflow
版权声明:本文标题:javascript - Can I showhide part of div? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744190929a2594513.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论