利用CSS&jQuery的简单滑动内容展示
四月 8, 2010 by zeze · Leave a Comment
切换教程已经有很多了,正在学习jQuery的基础知识和切换效果,我很难找到关于如何切换“开放”和“关闭”状态的资源。
在阅读了一些教程和混合和匹配技术,能达到这个效果。

>> View Demo
Step1. Wireframe & Style
HTML
<h2><a href="#">Toggle Header</a></h2>
<div>
<div>
<h3>Content Header</h3>
<!--Content-->
</div>
</div>
CSS
h2.trigger {
padding: 0 0 0 50px;
margin: 0 0 5px 0;
background: url(h2_trigger_a.gif) no-repeat;
height: 46px;
line-height: 46px;
width: 450px;
font-size: 2em;
font-weight: normal;
float: left;
}
h2.trigger a {
color: #fff;
text-decoration: none;
display: block;
}
h2.trigger a:hover { color: #ccc; }
h2.active {background-position: left bottom;} /*--When toggle is triggered, it will shift the image to the bottom to show its "opened" state--*/
.toggle_container {
margin: 0 0 5px;
padding: 0;
border-top: 1px solid #d6d6d6;
background: #f0f0f0 url(toggle_block_stretch.gif) repeat-y left top;
overflow: hidden;
font-size: 1.2em;
width: 500px;
clear: both;
}
.toggle_container .block {
padding: 20px; /*--Padding of Container--*/
background: url(toggle_block_btm.gif) no-repeat left bottom; /*--Bottom rounded corners--*/
}
Step2. Activating the Toggle with jQuery
jQuery
We will now activate this toggle effect with some simple jQuery.
$(document).ready(function(){
//Hide (Collapse) the toggle containers on load
$(".toggle_container").hide();
//Switch the "Open" and "Close" state per click
$("h2.trigger").toggle(function(){
$(this).addClass("active");
}, function () {
$(this).removeClass("active");
});
//Slide up and down on click
$("h2.trigger").click(function(){
$(this).next(".toggle_container").slideToggle("slow");
});
});
相关文章
« 上页 62个免费的高质量XHTML模板CSS和jquery做的自动图像滑块效果 下页 »