CSS3模拟IOS滑动开关效果

2020-05-06 09:13:45易采站长站整理

            width: 2rem;   
            height: 1rem;   
            background: #ccc;   
            border-radius: 5rem;   
            cursor: pointer;   
            position: relative;   
            -webkit-transition: all .3s ease;   
            transition: all .3s ease;   
        }   
  
        /* ==========================================================================   
                    设置伪类,来实现模拟滑块滑动,过渡用了transition来实现 ,   
                    translateZ来强制启用硬件渲染      
       ========================================================================== */   
  
        .emulate-ios-button:after {   
            content: ”;   
            display: block;   
            width: .9rem;   
            height: .9rem;   
            border-radius: 100%;   
            background: #fff;   
            box-shadow: 0 1px 1px rgba(0, 0, 0, .1);   
            position: absolute;   
            left: .05rem;   
            top: .05rem;   
            -webkit-transform:translateZ(0);