微调器径向颜色条
Spinner radial color bar
本文关键字:颜色 更新时间:2023-09-26
我想创建这样的视频效果:http://youtube.com/watch?v=bEVjLfq9lvk
我想创建微调器颜色,文本在中心,当颜色栏完全完成(100%)添加一些事件。我认为使用插件更简单,但我不是任何人,它应该与Ionic一起工作。如何为我的应用程序创建此模块?
好吧,既然你想有一个时间条,我前段时间自己做了一些东西。请注意,这种解决方案并不是最好的,因为存在舍入误差,这会使杆变得稍微太长或太短,而不是根据其宽度精确地达到100%。我相信有更好的解决方案,但这就是我现在得到的:
https://jsfiddle.net/a6wogez6/1/
HTML:
<div id="timebg">
</div>
<div id="time">
</div>
CSS:
#timebg{
height: 20px;
width: 300px;
background: #cc0000;
}
#time{
margin-top: -20px;
height: 20px;
width: 0px;
background: #00cc00;
}
Javascript:
var timerrunning;
var width;
var currentwidth;
var intervaltime;
function init() {
timerrunning = false;
width = document.getElementById("timebg").offsetWidth;
currentwidth = 0;
// interval steps to increase the timing bar by 3px
// 5 Seconds/(width of the bar) * 3 for 3px per step
intervaltime = Math.floor(5000/Math.floor(width))*3;
}
function gameStart(){
// your game starts, you start the timer
startTimer();
// timer times out after 5 seconds, the bar will be at 100%
timeout = setTimeout(function () {
stopTimer();
// do something here like gameOver()
}, 5000);
}
// function which starts the timer
function startTimer(){
timerrunning = true;
timer = setInterval(function(){loop()}, intervaltime);
}
// function which stops the timer and your timeout = level completed before time ran out
function stopTimer(){
timerrunning = false;
clearInterval(timer);
}
// the function which increases the width of the timing bar
function loop(){
currentwidth = currentwidth + 3;
css( '#time', 'width', currentwidth + 'px');
}
// some css selecting function I found somewhere...
function css(selector, property, value) {
for (var i=0; i<document.styleSheets.length;i++) {//Loop through all styles
//Try add rule
try { document.styleSheets[i].insertRule(selector+ ' {'+property+':'+value+'}', document.styleSheets[i].cssRules.length);
} catch(err) {try { document.styleSheets[i].addRule(selector, property+':'+value);} catch(err) {}}//IE
}
}
相关文章:
- 使用JS如何动态更改显示的html文件中的文本背景颜色
- 高亮显示时编辑文本大小和颜色
- 用与线条相同的颜色填充多折线图上的点
- 更改使用Chart.js创建的图表中的轴线颜色
- 如何使用jquery更改html中的背景颜色
- 动态更改高图中的系列颜色
- jsf中两个字符串的颜色代码差异
- 我们如何使用css或JavaScript在i/j上更改句点(点)的颜色
- d3.hexbin插件-动态定义颜色域以适应数据
- 我如何制作一个JS函数,它可以从相似的原始颜色双向更改为某个颜色
- 每个选择器的Jquery css颜色都在变化,但字体大小却没有变化
- Javascript对象类在单击时打开窗口进行颜色选择,并在更改时替换对象背景颜色
- jQuery动画-边框宽度和颜色
- JS幻灯片与CSS背景颜色变化
- 使用CSS/JavaScript更改剑道图工具提示文本颜色
- 使用Angular单击时更改特定图示符图标的颜色
- 如何使用D3生成特定范围内的随机颜色
- 比较javascript中的浮动并更改最高浮动的颜色
- 改变所有<td>为特定的桌子点击颜色
- 如何获得随机灯光颜色