使div具有动画效果并顺时针旋转。即Div的径向扫描时钟效果

时间:2013-01-17 07:26:26

标签: jquery css animation jquery-animate jquery-effects

我一直在谷歌搜索像here这样的div效果。
这里使用< canvas >来绘制图像 “放射状时钟效果
我怎样才能做到这一点 我找到了this javascript库。但它仅为图像提供此效果 我对div需要同样的效果 有什么方法可以做到这一点。
提前谢谢。

3 个答案:

答案 0 :(得分:2)

我创建了一个1/2时钟动画效果,类似于你想要的效果。我希望找到提供精确动画的解决方案。

代码

您需要为动画添加一些标记:

<div class="wrapper">
  <div class="content">
    This is a good day. Maybe.
  </div>
  <div class="rotate"></div>
  <div class="mask"></div>
</div>
  • 包装 - 用于设置内容的位置
  • 内容 - 您在div(或任何其他元素)中的内容
  • 旋转 - 动画以模拟1/2时钟
  • 掩码 - 隐藏content
  • 的动画

这是CSS(用SCSS编写):

变量

$width: 200px;
$height: 200px;
$duration: 2s;
$delay: 1s;
$color-alpha: #308991;
$color-beta: #80c144;
$color-gamma: #b83d54;

.wrapper {
  position:relative;
  width: $width;
  height: $height;
  margin:0 auto;
}

.content {
  width: $width;
  height: $height;
  background: $color-beta;
  border-radius: 50%;
  padding: 2em;
  overflow: hidden;
  text-align:center;
}

/* Rotates 360 deg */
.rotate {
  position: absolute; 
  z-index: 2;
  top: 0;
  right: 0;
  width: $width / 2;
  height: $height;
  box-shadow:0 0 0 .15em $color-alpha;
  background: $color-alpha;
  transform-origin: 0 50%;
  animation: rotate $duration linear 1 forwards;
  animation-delay: 1s;
}

@keyframes rotate {
  0%   { 
    transform: rotate(0deg);
  }
  62% {
    opacity:1;
  }
  99.99% {
    z-index: 2;
  }
  100% { 
    transform: rotate(360deg);
    opacity: 0;
    z-index: -1;
  }
}

/* The .content is hidden by .mask until the .rotate reveals it */
.mask {
  position:absolute;
  z-index:1;
  top: -1px;
  left: -1px;
  width: $width + 2px;
  height: $height + 2px;
  background: 
    linear-gradient(top, transparent 50%, $color-alpha 50%),
    linear-gradient(top, $color-alpha 50%, transparent 50%);
  background: 
    linear-gradient(to top, transparent 50%, $color-alpha 50%),
    linear-gradient(to top, $color-alpha 50%, transparent 50%);
  background-position:100% 100%, 0 0;
  background-size: 50% 200%;
  background-repeat: no-repeat;
  border-radius: 50%;
  box-shadow:0 0 0 .65em $color-alpha;

  animation: mask $duration / 1.25 linear 1 forwards; 
  animation-delay: (-$duration / 7.5) + $delay;
}

@keyframes mask {
  50% {
    background-position: 100% 0, 0 0;
  }

  99.99% {
    z-index: 1;
  }

  100% {
    background-position: 100% 0, 0 100%;
    z-index: -1;
  }
}

演示

您可以在CodePen上看到现场演示:1/2 clock animation

答案 1 :(得分:0)

此脚本可以将html转换为图像。 http://html2canvas.hertzen.com/

答案 2 :(得分:0)

如果我理解得很好,那么你正在寻找一个派对计时器效果。这是我刚才做过的纯CSS:http://css-tricks.com/css-pie-timer/

相关问题