美文网首页
样式(2) -- checkbox2

样式(2) -- checkbox2

作者: 卡拉咖啦 | 来源:发表于2019-10-17 23:44 被阅读0次

preview

demo预览

checkbox2

description

相比昨天的样式:
1.switcher 加入阴影,宽度可调节;
2.采用 cubic-bezier 生成回弹动画效果;
3.按钮与背景间隙可调节;

scss


* { padding: 0; margin: 0; box-sizing: border-box; }
*::after{ box-sizing: border-box; }

$checkboxSize: 30px;
$checkboxWidthTimes: 2.2;
$switcherWidthTimes: 1.1; /* 可以是椭圆形的内部按钮,可自行设置宽高比 */
$checkboxWidth: $checkboxWidthTimes * $checkboxSize;
$switcherWidth: $checkboxSize * $switcherWidthTimes;
$checkboxBackgroundForOFF: #f0f0f0;
$checkboxBackgroundForON: #86d993;
$checkboxButtonColor: #fff;
$interspace: 3px; /* 按钮与背景边框间隙大小 */

.checkboxWrapper {
  width: $checkboxWidth;
  height: $checkboxSize;
  position: relative;

  & label {
    display: block;
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    width: $checkboxWidth + 2 * $interspace;
    height: $checkboxSize + 2 * $interspace;
    box-sizing: content-box;
    border-radius: $checkboxWidth;
    background-color: $checkboxBackgroundForOFF;
    transition: all 0.2s ease;
    overflow: hidden;

    &::after {
      content: "";
      width: $switcherWidth;
      height: $checkboxSize;
      background-color: $checkboxButtonColor;
      transition: left 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
      border-radius: 2 * $switcherWidth;
      position: absolute;
      top: $interspace;
      left: $interspace;
      box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.1), 0 4px 0 rgba(0, 0, 0, 0.08);
    }
  }

  & input:checked + label{
    background-color: $checkboxBackgroundForON;
    border-color: $checkboxBackgroundForON;
    &::after{
      left: $checkboxWidth - $switcherWidth + $interspace;
    }
  }

  & input {
    opacity: 0;
  }
}

相关文章

  • 样式(2) -- checkbox2

    preview demo预览 description 相比昨天的样式:1.switcher 加入阴影,宽度可调节;...

  • 样式(6) -- checkbox6

    preview demo预览 description 这个 checkbox 是在 checkbox2 的基础上,...

  • 2018-03-14 RecyclerView 展示不同条目信息

    结构分析 1,有多少种item的样式 2,每个位置展示的样式及数据 样式格式 1,头部样式 2,条目样式 3,分割...

  • day07

    今天所学 1.1css样式的引入 1.内部样式表2.内联样式表3.外部样式表 样式引入.PNG 样式引入2.PNG...

  • React Native StryleSheet 实践总结

    1) 引入样式 2) 创建样式 3) 调用样式的几种方式 单个样式引用(对象) 多个样式引用(数组) 条件样式 ...

  • 样式(2)

    =<字体> - 标签可定义标题。 定义最大的标题。 定义最小的标题,独居一行。 text align: c...

  • js高级程序设计20

    样式 1.访问元素样式 2.DOM样式属性和方法 5.计算样式

  • day07(表单)

    布局 样式1内联样式(不用) 2内部样式 *{} 3外部样式

  • CSS的三种嵌入方式

    1.行内样式 2.页内样式 3.外部样式

  • CSS修饰

    1. 内部样式 2. 内联样式 3. 引用外部样式 内部样式如下: 内联样式如下: 引用外部样式 优先级:内联样式...

网友评论

      本文标题:样式(2) -- checkbox2

      本文链接:https://www.haomeiwen.com/subject/tgebmctx.html