前端 html+css+javascript 选项卡切换效果

本文介绍了如何使用HTML、CSS和JavaScript实现一个选项卡切换效果,包括对应的代码示例,帮助读者理解前端交互设计的基本原理。
摘要由CSDN通过智能技术生成

效果图:

html代码:

<div id="divPage" style="width:800px;height:750px;padding:10px;background:#fafafa;">
    <p style="margin-bottom:20px;">
	    <a class="sel_btn ch_cls" id="sel_btn1" href="javascrip:;"
                onclick="changeSelBtn(1)">测试方案1</a>
			<span class="arrowRight"></span>
	    <a class="sel_btn" id="sel_btn2" href="javascrip:;" 
                onclick="changeSelBtn(2)">测试方案2</a>
		    <span class="arrowRight"></span>
	    <a class="sel_btn" id="sel_btn3" href="javascrip:;" 
                onclick="changeSelBtn(3)">测试方案3</a>
	</p>
	<div class="demoPage showPage" id="demoPage1">
	    <p>方案1</P>
	</div>
	<div class="demoPage" id="demoPage2">
	    <p>方案2</P>
	</div>
	<div class="demoPage" id="demoPage3">
	    <p>方案3</P>
	</div>
</div>

css代码:

/*按钮样式切换*/
.sel_btn{
    width: 140px;
    height: 40px;
    line-height: 40px;
    padding: 0 11px;
    background: inherit;
    background-color: #e4e4e4;
    border: 1px solid rgba(22, 155, 213, 1);
    border-radius: 5px;
    display: inline-block;
    text-decoration: none;
    font-family: 'Arial Normal', 'Arial';
    font-weight: 400;
    font-style: normal;
    font-size: 12px;
    outline: none;
    text-align: center;
    color: rgba(22, 155, 213, 1);
}
.ch_cls{
    background: rgba(22, 155, 213, 1);
    color: #fff;
}
/*箭头容器*/
.arrowRight{
    width:40px;
    height:13px;
    display: inline-block;
    position: relative;
}
.arrowRight:before,.arrowRight:after{
    content: '';
    border-color: transparent;
    border-style: solid;
    position: absolute;
}
.arrowRight:after{
    width: 60%;
    height: 30%;
    background-color: #555;
    top: 5px;
    left: 0;
}
.arrowRight:before{
    border-left-color: #555;
    border-width: 10px;
    left: 30px;
    top: 0;
}
.packagesopTable tr td{
    width: 90px;
    height:30px;
    text-align: center;
}
/*DIV显示控制*/
.demoPage{
    display:none;
}
.showPage{
    display:block;
}

javascript代码:

function changeSelBtn(index){
    if(index!=null){
        // 按钮
    	$(".sel_btn").removeClass('ch_cls');
    	$("#sel_btn"+index).addClass('ch_cls');
    	// DIV
    	$(".demoPage").removeClass('showPage');
    	$("#demoPage"+index).addClass('showPage');
    }
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

superSubfn

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

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

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

打赏作者

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

抵扣说明:

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

余额充值