CSS动画复选标记

Me *_*hdi 4 html javascript css jquery css3

我想要crate一个动画的Check-mark CSS(用SVG动画制作复选标记的动画),我尝试了下面的代码,但它不起作用.我该怎么办?

演示: https ://jsfiddle.net/b7Ln0jns/

CSS:

@import "bourbon";

$color--green: #7ac142;
$curve: cubic-bezier(0.650, 0.000, 0.450, 1.000);

.checkmark__circle {
  stroke-dasharray: 166;
  stroke-dashoffset: 166;
  stroke-width: 2;
  stroke-miterlimit: 10;
  stroke: $color--green;
  fill: none;
  animation: stroke .6s $curve forwards;
}

.checkmark {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  display: block;
  stroke-width: 2;
  stroke: #fff;
  stroke-miterlimit: 10;
  margin: 10% auto;
  box-shadow: inset 0px 0px 0px $color--green;
  animation: fill .4s ease-in-out .4s forwards, scale .3s ease-in-out .9s both;
}

.checkmark__check {
  transform-origin: 50% 50%;
  stroke-dasharray: 48;
  stroke-dashoffset: 48;
  animation: stroke .3s $curve .8s forwards;
}

@keyframes stroke {
  100% {
    stroke-dashoffset: 0;
  }
}

@keyframes scale {
  0%, 100% {
    transform: none;
  }
  50% {
    transform: scale3d(1.1, 1.1, 1);
  }
}

@keyframes fill {
  100% {
    box-shadow: inset 0px 0px 0px 30px $color--green;
  }
}
Run Code Online (Sandbox Code Playgroud)

JS:

<svg class="checkmark" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 52 52"><circle class="checkmark__circle" cx="26" cy="26" r="25" fill="none"/><path class="checkmark__check" fill="none" d="M14.1 27.2l7.1 7.2 16.7-16.8"/></svg>
Run Code Online (Sandbox Code Playgroud)

Mic*_*ael 15

看一下这个演示 - 由于你使用的是css文件,你需要将scss转换为css.

更新的CSS:

.checkmark__circle {
  stroke-dasharray: 166;
  stroke-dashoffset: 166;
  stroke-width: 2;
  stroke-miterlimit: 10;
  stroke: #7ac142;
  fill: none;
  animation: stroke 0.6s cubic-bezier(0.65, 0, 0.45, 1) forwards;
}

.checkmark {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  display: block;
  stroke-width: 2;
  stroke: #fff;
  stroke-miterlimit: 10;
  margin: 10% auto;
  box-shadow: inset 0px 0px 0px #7ac142;
  animation: fill .4s ease-in-out .4s forwards, scale .3s ease-in-out .9s both;
}

.checkmark__check {
  transform-origin: 50% 50%;
  stroke-dasharray: 48;
  stroke-dashoffset: 48;
  animation: stroke 0.3s cubic-bezier(0.65, 0, 0.45, 1) 0.8s forwards;
}

@keyframes stroke {
  100% {
    stroke-dashoffset: 0;
  }
}
@keyframes scale {
  0%, 100% {
    transform: none;
  }
  50% {
    transform: scale3d(1.1, 1.1, 1);
  }
}
@keyframes fill {
  100% {
    box-shadow: inset 0px 0px 0px 30px #7ac142;
  }
}
Run Code Online (Sandbox Code Playgroud)

HTML

<svg class="checkmark" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 52 52">
    <circle class="checkmark__circle" cx="26" cy="26" r="25" fill="none"/>
    <path class="checkmark__check" fill="none" d="M14.1 27.2l7.1 7.2 16.7-16.8"/>
</svg>
Run Code Online (Sandbox Code Playgroud)

SASS&SCSS信息:

Sass是CSS3的扩展,添加了嵌套规则,变量,mixins,选择器继承等等.它使用命令行工具或web框架插件转换为格式良好的标准CSS.

Sass有两种语法.新的主要语法(从Sass 3开始)被称为"SCSS"(用于"Sassy CSS"),并且是CSS3语法的超集.这意味着每个有效的CSS3样式表也是有效的SCSS.SCSS文件使用扩展名.scss.

第二种较旧的语法称为缩进语法(或仅称为"Sass").受Haml的简洁启发,它适用于那些喜欢与CSS相似的简洁性的人.它使用行的缩进来指定块,而不是括号和分号.虽然不再是主要语法,但将继续支持缩进语法.缩进语法中的文件使用扩展名.sass.

  • @Alexandre A.,这就是你至少想要的红色 X 吗:https://jsfiddle.net/1taoqd9k/ (3认同)
  • @Vingtoft,请看一下该示例以进行放大:https://jsfiddle.net/gtb1avet/1586/-该示例演示了将其放大50像素-通过CSS部分,查找注释掉的内容:`/ *原始## px * /`-只需根据自己的喜好更改此注释的显示值-您可以缩小或放大:)希望有帮助! (2认同)
  • 你能制作一个红色 X 的动画来显示用户输入了不正确的内容吗 (2认同)
  • 谢谢@ThisGuy!我已经使用这个复选标记一千次了 ^^ (2认同)