The javaScript code is as follows:
$(document).ready(function(){ $(".message_list .message_body:gt(0)").hide(); $(".message_list li:gt(4)").hide(); $(".message_head").click(function(){ $(this).next(".message_body").slideToggle(500) return false; }); //Collapse all messages$(".collpase_all_message").click(function(){ $(".message_body").slideUp(500) return false; }); //Show all messages $(".show_all_message").click(function(){ $(this).hide() $(".show_recent_only").show() $(".message_list li:gt(4)").slideDown() return false; }); //Show only the most recent messages $(".show_recent_only").click(function(){ $(this).hide() $(".show_all_message").show() $(".message_list li:gt(4)").slideUp() return false; }); });Part of the code of css is as follows:
* { margin: 0; padding: 0; } body { margin: 10px auto; width: 570px; font: 75%/120% Arial, Helvetica, sans-serif; } p { padding: 0 0 1em; } .message_list { list-style: none; margin: 0; padding: 0; width: 383px; } .message_list li { padding: 0; margin: 0; background: url(images/message-bar.gif) no-repeat; } .message_head { padding: 5px 10px; cursor: pointer; position: relative; } .message_head .timestamp { color: #666666; font-size: 95%; position: absolute; right: 10px; top: 5px; } .message_head cite { font-size: 100%; font-weight: bold; font-style: normal; } .message_body { padding: 5px 10px 15px; } .collapse_buttons { text-align: right; border-top: solid 1px #e4e4e4; padding: 5px 0; width: 383px; } .collapse_buttons a { margin-left: 15px; float: right; } .show_all_message { background: url(images/tall-down-arrow.gif) no-repeat right center; padding-right: 12px; } .show_recent_only { display: none; background: url(images/tall-up-arrow.gif) no-repeat right center; padding-right: 12px; } .collpase_all_message { background: url(images/collapse-all.gif) no-repeat right center; padding-right: 12px; color: #666666;}Add code to HTML as follows:
<ol> <li> <p><cite>Zhang San:</cite> <span>1 minute ago</span></p> <div> <p>Hello<br /> <br /> This is the last message</p> </div> </li> <li> <p><cite>Li Si:</cite> <span>2 minutes ago</span></p> <div> <p>You are good</p> </div> </li> <li> <p><cite>Wang Wu:</cite> <span>1 day ago</span></p> <div> <p>First time</p> </li> <li> <p><cite>Li Si:</cite> <span> <span>2 days ago</span></p> <div> <p>Top</p> </div> </li> <li> <p><cite>Wang Wu:</cite> </cite> </cite> </li> <li> <p><cite>Wang Wu:</cite> </cite> </cite> </li> <li> <p><cite>Wang Wu:</cite> </cite> </cite> </li> <li> <p><cite> <span>3 days ago</span></p> <div> <p>Support</p> </div> </li> <li> <p><cite>Li Si:</cite> <span>5 days ago</span></p> <div> <p>Hello everyone</p> </div> </li> <li> <p><cite>Zhang San:</cite> <span> <span>6 days ago</span></p> <div> <p>Hello everyone</p> </div> </li> <li> <p><cite>Li Si:</cite> <span>7 days ago</span></p> <div> <p>This is good</p> </div> </li> <li> <p><cite>Wang Wu:</cite> <span> <span>8 days ago</span></p> <div> <p>Good place</p> </div> </li> </ol> <p><a href="#">Show all messages (9)</a> <a href="#">Show only five messages</a> <a href="#">Collapse all messages</a></p> <br />
Case download