javascript - 半圆动画从按钮单击开始

标签 javascript html animation onclick

我正在尝试让我的圆圈加载程序运行。但没有找到如何在点击Try it按钮时让动画运行。

有什么想法吗?

<div class="chart-skills">
  <div class="liElem" id="eins"></div>
</div>

<div class="chart-skills" id="bottom">
  <div class="liElem" id="zwei"></div>
</div>

<button onclick="myFunction()">Try it</button>

这里的代码:https://jsfiddle.net/pzc41skn/

最佳答案

以下是如何在单击按钮时实现动画:

function myFunction() {
  $('.liElem').remove();
  $(".chart-skills").html('<div class="liElem" id="eins"></div>');
}
body {
  font: normal 16px/1.5 'Roboto', sans-serif;
  padding: 130px 0 0 0;
  background: #f1f1f1;
}


/* RESET STYLES
–––––––––––––––––––––––––––––––––––––––––––––––––– */

.chart-skills {
  margin: 0 auto;
  padding: 0;
  list-style-type: none;
}

.chart-skills *,
.chart-skills::before {
  box-sizing: border-box;
}


/* CHART-SKILLS STYLES
–––––––––––––––––––––––––––––––––––––––––––––––––– */

.chart-skills {
  position: relative;
  width: 350px;
  height: 175px;
  overflow: hidden;
}

.chart-skills::before,
.chart-skills::after {
  position: absolute;
}

.chart-skills::before {
  content: '';
  width: inherit;
  height: inherit;
  border: 45px solid rgba(211, 211, 211, .3);
  border-bottom: none;
  border-top-left-radius: 175px;
  border-top-right-radius: 175px;
}

.chart-skills::after {
  content: '';
  left: 50%;
  bottom: 10px;
  transform: translateX(-50%);
  font-size: 1.1rem;
  font-weight: bold;
  color: cadetblue;
}

.chart-skills .liElem {
  position: absolute;
  top: 100%;
  left: 0;
  width: inherit;
  height: inherit;
  border: 45px solid;
  border-top: none;
  border-bottom-left-radius: 175px;
  border-bottom-right-radius: 175px;
  transform-origin: 50% 0;
  transform-style: preserve-3d;
  backface-visibility: hidden;
  animation-fill-mode: forwards;
  animation-duration: .4s;
  animation-timing-function: linear;
}

.chart-skills #eins {
  z-index: 4;
  border-color: green;
  animation-name: rotate-one;
  animation-delay: .4s;
}

.chart-skills #zwei {
  z-index: 4;
  border-color: green;
  animation-name: rotate-one;
  animation-delay: .8s;
}



@keyframes rotate-one {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(180deg);
    /**
     * 32% => 57.6deg
     * 57.6 + 21.6 => 79.2deg
     */
  }
}

#bottom {
    transform: scale(-1);

}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="chart-skills">
  <div class="liElem" id="eins"></div>

</div>

<div class="chart-skills" id="bottom">
  <div class="liElem" id="zwei"></div>
</div>

<button onclick="myFunction()">Try it</button>

关于javascript - 半圆动画从按钮单击开始,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44242921/

相关文章:

javascript - struts2 jquery ajax 和客户端验证不能一起工作

javascript - 如何在固定标题上滚动内容?

html - 使用 width % 和 padding-bottom % 时方形 div 的固定大小

html - 使用 CSS 实现带有环状效果的行星

html - 表格树上的水平滚动条

javascript - 如何以与 vivus.js 类似的风格制作 SVG 填充和路径动画

ios - 当用户用手指拾取时的动画表格 View 单元格(Swift 3)

javascript - 动态显示tinymce textarea

javascript - 为什么会出现TypeError : Cannot read property 'completed' of undefined?

Javascript 使动画变慢?