jQuery_折叠效果

使用 jQuery 实现一个折叠效果。

效果图:

在线预览:jquery_fold

下载

兼容性:

demo 图标:

源码:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>jQuery_折叠效果</title>
</head>

<body>

<div class="fold_box">
    <div class="fold_tit">Tit 1 <span class="ico"></span></div>
    <div class="fold_con">Con 1</div>
    <div class="fold_tit">Tit 2 <span class="ico"></span></div>
    <div class="fold_con">Con 2</div>
    <div class="fold_tit">Tit 3 <span class="ico"></span></div>
    <div class="fold_con">Con 3</div>
</div>
<style>
.fold_box { width: 400px; margin: 20px auto; }
.fold_tit { position: relative; padding: 20px; border-bottom: 1px solid #dadada; background-color: #f5f5f5; }
.fold_tit .ico { position: absolute; top: 20px; right: 20px; width: 16px; height: 16px; background-image: url(fold_ico.png); background-repeat: no-repeat; background-position: left 0; }
.fold_tit.selected { color: red; background-color: #dadada; }
.fold_tit.selected .ico { position: absolute; top: 20px; right: 20px; width: 16px; height: 16px; background-image: url(fold_ico.png); background-repeat: no-repeat; background-position: right 0; }
.fold_con { display: none; padding: 20px; border: 1px solid #dadada; border-top: 0; }
</style>
<script src="jquery-1.8.3.min.js"></script>
<script>
$(function() {
    var showIndex = 0;
    $(".fold_tit").eq(showIndex).addClass('selected');
    $(".fold_con").eq(showIndex).show();
    $(".fold_tit").click(function(event) {
        event.preventDefault();
        $(this).toggleClass("selected").siblings('.fold_tit').removeClass("selected");
        $(this).next(".fold_con").slideToggle(400).siblings(".fold_con").slideUp(400);
    });
});
</script>

</body>

</html>
复制代码

期待您的关注!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值