码迷,mamicode.com
首页 > Web开发 > 详细

滑动开关效果 css3滑动开关】纯CSS3代码实现滑动开关效果-css3滑动效果-css3左右滑动

时间:2016-04-15 18:13:20      阅读:197      评论:0      收藏:0      [点我收藏+]

标签:

 今天看到一篇有关 css3事件的博文,一时兴起便整理下相关的资料。 点击按钮,可以实现开关的滑动效果。

 今天看到一篇有关 css3事件的博文,一时兴起便整理下相关的资料。 点击按钮,可以实现开关的滑动效果。

 今天看到一篇有关 css3事件的博文,一时兴起便整理下相关的资料。 点击按钮,可以实现开关的滑动效果。

.toggle input:checked + .ss div {
transform: translate3d(60px, 0, 0);
background-color: #fff;
}
.has-switch {
display: inline-block;
cursor: pointer;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
border: 1px solid;
border-color: rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.25);
position: relative;
text-align: left;
overflow: hidden;
line-height: 8px;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
-o-user-select: none;
user-select: none;
min-width: 100px;
}
.has-switch > div.switch-on {
left: 0%;
}
.has-switch > div.switch-animate {
-webkit-transition: left 0.5s;
-moz-transition: left 0.5s;
-o-transition: left 0.5s;
transition: left 0.5s;
}
.has-switch > div {
display: inline-block;
width: 150%;
position: relative;
top: 0;
}
.has-switch span.switch-left {
color: #ffffff;
text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.25);
background-color: #005fcc;
background-image: -moz-linear-gradient(top, #0044cc, #0088cc);
background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#0044cc), to(#0088cc));
background-image: -webkit-linear-gradient(top, #0044cc, #0088cc);
background-image: -o-linear-gradient(top, #0044cc, #0088cc);
background-image: linear-gradient(to bottom, #0044cc, #0088cc);
background-repeat: repeat-x;
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=‘#ff0044cc‘, endColorstr=‘#ff0088cc‘, GradientType=0);
border-color: #0088cc #0088cc #005580;
border-color: rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.25);
filter: progid:DXImageTransform.Microsoft.gradient(enabled = false);
}
.has-switch span.switch-left {
-webkit-border-top-left-radius: 4px;
-moz-border-radius-topleft: 4px;
border-top-left-radius: 4px;
-webkit-border-bottom-left-radius: 4px;
-moz-border-radius-bottomleft: 4px;
border-bottom-left-radius: 4px;
}
.has-switch span {
text-align: center;
z-index: 1;
width: 33%;
}
.has-switch span, .has-switch label {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
cursor: pointer;
position: relative;
display: inline-block;
height: 100%;
padding-bottom: 4px;
padding-top: 4px;
font-size: 14px;
line-height: 20px;
}
.has-switch label {
text-align: center;
margin-top: -1px;
margin-bottom: -1px;
z-index: 100;
width: 34%;
border-left: 1px solid #cccccc;
border-right: 1px solid #cccccc;
color: #ffffff;
text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.25);
background-color: #f5f5f5;
background-image: -moz-linear-gradient(top, #ffffff, #e6e6e6);
background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#ffffff), to(#e6e6e6));
background-image: -webkit-linear-gradient(top, #ffffff, #e6e6e6);
background-image: -o-linear-gradient(top, #ffffff, #e6e6e6);
background-image: linear-gradient(to bottom, #ffffff, #e6e6e6);
background-repeat: repeat-x;
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=‘#ffffffff‘, endColorstr=‘#ffe6e6e6‘, GradientType=0);
border-color: #e6e6e6 #e6e6e6 #bfbfbf;
border-color: rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.25);
filter: progid:DXImageTransform.Microsoft.gradient(enabled = false);
}
.has-switch span, .has-switch label {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
cursor: pointer;
position: relative;
display: inline-block;
height: 100%;
padding-bottom: 4px;
padding-top: 4px;
font-size: 14px;
line-height: 20px;
}
.has-switch span.switch-right {
color: #333333;
text-shadow: 0 1px 1px rgba(255, 255, 255, 0.75);
background-color: #f0f0f0;
background-image: -moz-linear-gradient(top, #e6e6e6, #ffffff);
background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#e6e6e6), to(#ffffff));
background-image: -webkit-linear-gradient(top, #e6e6e6, #ffffff);
background-image: -o-linear-gradient(top, #e6e6e6, #ffffff);
background-image: linear-gradient(to bottom, #e6e6e6, #ffffff);
background-repeat: repeat-x;
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=‘#ffe6e6e6‘, endColorstr=‘#ffffffff‘, GradientType=0);
border-color: #ffffff #ffffff #d9d9d9;
border-color: rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.25);
filter: progid:DXImageTransform.Microsoft.gradient(enabled = false);
}
.has-switch span {
text-align: center;
z-index: 1;
width: 33%;
}
.has-switch span, .has-switch label {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
cursor: pointer;
position: relative;
display: inline-block;
height: 100%;
padding-bottom: 4px;
padding-top: 4px;
font-size: 14px;
line-height: 20px;
}
.has-switch input[type=checkbox] {
display: none;
}
.has-switch > div.switch-off {
left: -50%;
}

html部分



<div class="switch has-switch">
<div class="switch-on switch-animate"><input type="checkbox" checked="">
<span class="switch-left">ON</span><label>
&nbsp;</label><span class="switch-right">OFF</span>
</div>
</div>

js部分
 
<script src="jquery.min.js"></script>
<script>
$(function(){
var animate=$(".switch-animate");
animate.on("click",function(){
if ($(this).hasClass("switch-on")){
$(this).removeClass("switch-on").addClass("switch-off");
}
else {
$(this).addClass("switch-on").removeClass("switch-off");
}
})

})
</script>


滑动开关效果 css3滑动开关】纯CSS3代码实现滑动开关效果-css3滑动效果-css3左右滑动

标签:

原文地址:http://www.cnblogs.com/znj211985211/p/5396270.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!