动画围绕圆形按钮的条形图

时间:2017-06-10 19:44:25

标签: css css3

我正在尝试实现按下按钮时应该为按钮周围的条形图设置动画。

这是我的按钮css

>>> import bs4
>>> import requests
>>> soup_2 = bs4.BeautifulSoup(requests.get('http://www.kegg.jp/entry/ag:CAA27061').content, 'lxml')
>>> organism = soup_2.find_all('nobr', string='Organism')
>>> parentDiv = organism[0].fetchParents()[0].fetchNextSiblings()[0].find_all('div')[0]
>>> desiredContent = [_.strip() for _ in parentDiv.contents if not _.name and _.strip()]
>>> if desiredContent:
...     m = bs4.re.match('[^\(]*\(([^\)]+)', desiredContent[0])
...     if m:
...         name = m.groups()[0]
...     else:
...         name = "Couldn't match content of " + desiredContent
...         
>>> name
'Bacillus circulans'
button {
  border: none;
  cursor: pointer;
  color: white;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  font-size: 22px;
  box-shadow: 2px 2px 4px rgba(0, 0, 0, .4);
  background: #2196F3;
}

button {
  position: relative;
  overflow: hidden;
}

button:after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 5px;
  height: 5px;
  background: rgba(255, 255, 255, .5);
  opacity: 0;
  border-radius: 100%;
  transform: scale(1, 1) translate(-50%);
  transform-origin: 50% 50%;
}

@keyframes ripple {
  0% {
    transform: scale(0, 0);
    opacity: 1;
  }
  20% {
    transform: scale(25, 25);
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: scale(40, 40);
  }
}

button:focus:not(:active)::after {
  animation: ripple 1s ease-out;
}

https://jsfiddle.net/k1a3ha4c/2/

我无法想到CSS3中的逻辑如何在按钮周围创建加载栏。有人可以帮忙吗?

1 个答案:

答案 0 :(得分:1)

你可以添加一个伪前元素,然后按照makeFirstResponder关于如何制作一个加载器。

我提供的示例创建了一个伪animation: spin 1s cubic-bezier(0.46, 0.03, 0.52, 0.96) 1;元素,该元素具有1/4圆绿色边框,当单击该按钮时,将调用旋转动画,该旋转动画以易于进出的效果旋转元素。 button { border: none; cursor: pointer; color: white; width: 60px; height: 60px; border-radius: 50%; font-size: 22px; box-shadow: 2px 2px 4px rgba(0, 0, 0, .4); background: #2196F3; outline: none; } button { position: relative; // overflow: hidden; } button:after { content: ''; position: absolute; width: 60px; height: 60px; top: -5px; left: -5px; transform-origin: 50% 50%; border: 5px solid rgba(0, 0, 0, 0); border-top: 5px solid #008744; border-radius: 50%; opacity: 0; } button:before { content: ''; position: absolute; top: 50%; left: 50%; width: 5px; height: 5px; background: rgba(255, 255, 255, .5); opacity: 0; border-radius: 50%; transform: scale(1, 1) translate(-50%); transform-origin: 50% 50%; } @keyframes ripple { 0% { transform: scale(0, 0); opacity: 1; } 20% { transform: scale(15, 15); opacity: 1; } 100% { transform: scale(20, 20); opacity: 0; } } @keyframes spin { 0% { opacity: 1; transform: rotate(0deg); } 100% { opacity: 1; transform: rotate(360deg); } } button:focus:not(:active)::before { animation: ripple 1s ease-out; } button:focus:not(:active)::after { animation: spin 1s cubic-bezier(0.46, 0.03, 0.52, 0.96) 1; }

示例:



<button>
+
</button>
&#13;
{{1}}
&#13;
&#13;
&#13;

希望这有帮助!