【发布时间】:2020-01-08 17:22:39
【问题描述】:
我遇到了这个问题,我试图根据时间移动 CSS 图像,但由于它在 CSS 中,所以无法使用它。特征不是太阳,而是在这个pen 中可以看到的黄色半圆动画。我正在尝试将该半圆应用于完全随机的形状。
例如,如果形状是完全随机的并且在白色画布上并且中间有一个随机变形的圆圈,那么如何使用与pen 中看到的相同的动画填充该圆圈以及如何转换将 CSS 转换为 javascript 或如何控制 CSS,因为在设置某些值时它必须停止和移动。
我不指望有人会做所有事情,而是可能会在我需要使用那支笔中的黄色功能时帮助我应该从哪里开始。
谢谢。
事情就是这样。
<div class="sunmoon">
<h2>Sun & Moon</h2>
<div class="sun-times">
<div class="sun-path">
<div class="sun-animation"></div>
</div>
<div class="sun-symbol-path"><span class="symbol">☀</span></div>
</div>
<div class="legend">
<div class="sunrise">05:30 AM</div>
<div class="sunset">8:04 PM</div>
</div>
<div class="clear"> </div>
</div>
<div class="controls">
<button class="start">Start</button>
<button class="reset">Reset</button>
</div>
@import "compass/css3";
$arc-diameter: 170px;
.sunmoon {
position: relative;
& > div {
margin-left: 10px
}
}
.sun-times {
margin-top: 40px;
width: 230px;
height: 60px;
border-bottom: 1px solid #999;
overflow-y: hidden;
.sun-path {
margin-left: 25px;
width: $arc-diameter;
height: $arc-diameter;
overflow: hidden;
border: 1px dashed #999;
border-radius: 50%;
}
.sun-symbol-path {
position: absolute;
color: yellow;
text-shadow: 0 0 5px black;
height: $arc-diameter / 2;
-webkit-transition: -webkit-transform 2s linear;
-webkit-transform-origin: 50% 100%;
-webkit-transform: rotateZ(-75deg);
left: ($arc-diameter / 2) + 25px;
bottom: 0;
.symbol {
position: relative;
font-size: 16px;
top: -8px;
}
}
.sun-animation {
width: 0px;
height: 150px;
background-color: rgba(255, 255, 0, 0.4);
-webkit-transition: width 2s linear;
transition: width 2s linear;
}
}
.legend {
position: absolute;
bottom: 1em;
& > div {
position: absolute;
font-size: 12px;
width: 80px;
}
.sunrise {
left: 15px;
}
.sunset {
left: 185px;
}
}
body {
background-image: url(foo);
background-color: #ccc;
font-family: Helvetica, Sans serif;
h2 {
font-size: 20px;
}
}
.controls {
margin-top: 50px;
}
$('.start').click(function () {
$('.sunmoon .sun-animation').css('width', '70%');
$('.sun-symbol-path').css('-webkit-transform', 'rotateZ(27deg)');
// TODO: mention that this isn't nice
// city.find('.sunmoon .sun-animation').css('-webkit-transform', 'scaleX(50)');
return false;
});
$('.reset').click(function () {
$('.sun-animation').css('width', '0%');
$('.sun-symbol-path').css('-webkit-transform', 'rotateZ(-75deg)');
return false;
});
【问题讨论】:
-
抱歉,剪得乱七八糟,正在修复中
-
你的直觉是正确的,这个问题太宽泛了。您可能想使用画布进行调查,或者您可以将您的形状叠加为蒙版,这样您的动画区域实际上不需要是一个奇怪的形状。
-
使用 HTML5 画布或众所周知的动画工具包。您现在拥有的代码绝对会通过重新渲染对您的浏览器造成伤害,而且将其解码为 JS 的时间可能比从头开始构建它更多的是机会成本。
标签: javascript jquery html css weather