js tab切换效果

<html>
<head>
    <title>tab</title>
    <style type="text/css">
        body
        {
            margin-top: 0px;
            margin-left: 0px;
            margin-bottom: 0px;
            margin-right: 0px;
        }
        .scroll
        {
            border: 2px solid #ccc;
        }
        .tabdiv
        {
            width: 716px;
        }
        .tabHead
        {
            height: 35px;
        }
        ul.tabul
        {
            margin: 0px;
            padding: 0px;
            height: 35px;
        }
        ul.tabul li
        {
            list-style-type: none;
            margin: 0px;
            float: left;
        }
        ul.tabul li a, ul.tabul li a:visited
        {
            display: block;
            text-decoration: none;
            background: url('images/blue2.jpg') -424px 0px;//默认情况下的图片,根据自已的需要时行修改
            background-repeat: no-repeat;
            width: 130px;
            height: 35px;
            line-height: 35px;
            text-align: center;
        }
        ul.tabul li a:hover
        {
            /*background:url('images/blue2.jpg') -424px -70px;*/
            background-repeat: no-repeat;
        }
        .tabContent
        {
            border-left: 1px solid #ccc;
            border-right: 1px solid #ccc;
            border-bottom: 1px solid #ccc;
        }
        ul.tabul li a.selected
        {
            background: url('images/blue2.jpg') -424px -70px;//tab切换时的图片,根据自已的需要时行修改
            background-repeat: no-repeat;
        }
        li.last
        {
            width: 456px;
            height: 33px;
            border-bottom: 1px solid #ccc;
        }
    </style>
    <script src="js/jquery-1.4.2.min.js" type="text/javascript"></script>//借助了jquery
</head>
<body>

  <div class="tabdiv">
        <div class="tabHead">
            <ul class="tabul">
                <li><a href="#" class="selected">我的电脑</a></li><li><a href="#">我的新闻</a></li><li class="last"></li>
            </ul>
        </div>
        <div class="tabContent">
            我的电脑
        </div>
        <div class="tabContent">
            我的新闻
        </div>
    </div>
    <script language="javascript" type="text/javascript">
        function bindEvent() {//tab切换
            $("div.tabContent").each(function (i, n) { if (i == 0) return true; else { $(this).hide(); } });
            $(".tabHead>ul>li>a").each(function (i, n) {
                var numb = i;
                $(this).bind("mouseover", function () {
                    $(".tabHead>ul>li>a").each(function () {
                        if ($(this).hasClass("selected")) {$(this).removeClass("selected"); $("div.tabContent").each(function (a, k) { if (a == numb) { $(this).show(); } else { $(this).hide(); } }); return false;}});
                    $(this).addClass("selected");
                });
            });
        }
        bindEvent();
    </script>
</body>
</html>

background: url('images/blue2.jpg') -424px 0px;// blue2.jpg图片上传的附件中

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

kingboyrang

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值