css布局之选择切换按钮

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
	<title>Document</title>
</head>
<style>
	.btn-change{
		width: 120px;
		height: 40px;
		border-radius: 20px;
		border: 1px solid #dedede;
		font-size: 1.3em;
		margin: 0 auto;
		position: relative;
		overflow: hidden;
	}
	.btn-dot{
		height: 40px;
		width: 40px;
		background-color: #dedede;
		border-radius: 20px;
		position: absolute;
		z-index: 99;
	}

	.btn-left{
		background-color:#74B700; 
		position: absolute;
		width: 100px;
		height: 40px;
		line-height: 40px;
		left: -80px;
		color: #fff;
		text-align: left;
		padding-left: 40px;
	}
	
	.btn-move{
		position: absolute;
		left:0;
		-webkit-transition: all .3s;-moz-transition: all .3s;transition: all .3s;
	}

	.switch.btn-move{
		left:80px;
	}
	.btn-right{
		background-color: #ebebeb;
		position: absolute;
		width: 100px;
		height: 40px;
		line-height: 40px;
		text-align: left;
		padding-left: 20px;
		left: 20px;
		color: #333;
	}
	
</style>
<body>
<div class="btn-change">
	<div class="btn-move">
        <div class="btn-left">关注</div>
        <div class="btn-dot"></div>
        <div class="btn-right">未关注</div>
    </div>
</div>
</body>
</html>
<script src="jquery-1.10.2.js"></script>
<script>
	$(function(){
		$(".btn-move").click(function(){
			$(this).toggleClass("switch");
		})
	})
</script>

  

效果图:

posted @ 2015-04-16 19:10  徐航  阅读(614)  评论(0编辑  收藏  举报