仿iPhone的switch开关

看到很多iPhone上的滑动开关效果的button,今天终于有时间搞一下

其实很简单,也不难就是大量用到了CSS3的属性,不需要引入图片,但是要一点JS来控制

贴上效果图:

开启的时候


关闭的效果



代码在这里:

<!DOCTYPE html>
<html>
<head>
    <title>anmiation</title>
    <!-- 让IE采用最新的渲染模式 -->
    <meta http-equiv="X-UA-compatible" content="IE=edge">
    <!-- 移动端的页面宽度等于设备宽度,缩放比为1 -->
    <meta name="viewport" content="width=device-width" initial-scale="1">
    <meta charset="utf-8">

</head>
<style type="text/css" media="screen">
.switch-bg {
    width: 150px;
    height: 50px;
    background: #76d95c;
    border-radius: 50px;
    box-shadow:inset 0px 0px 3px;
    transition:all 0.5s;
}
.switch-block {
    width: 48px;
    height: 48px;
    background: #ffffff;
    border-radius: 50%;
    position: relative;
    top: 1px;
    left: 1px;
    box-shadow: 1px 3px 5px;
    transition:all 0.5s;
}
.turn-off {
    background: #ffffff;
}
.turn-off>.switch-block {
    left: 99px;
}
</style>
<body>
    <div class="switch-bg">
        <div class="switch-block"></div>
    </div>
    <script src="js/jquery-1.6.4.js"></script>
    <script>
    $(".switch-bg").click(function(){
        if($(this).hasClass("turn-off")){
            $(this).removeClass("turn-off");
            return;
        }
        $(this).addClass("turn-off");
    });
    </script>
</body>
</html>

用到了一点点的jquery

点击可以实现滑动哦

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值