【问题标题】:Spinner radial color bar微调器径向颜色条
【发布时间】:2015-10-30 23:09:27
【问题描述】:

我想制作这样的视频效果:http://youtube.com/watch?v=bEVjLfq9lvk

我想用文本在中心创建微调器颜色,并在颜色条完全完成(100%)时添加一些事件。 我认为使用插件更简单,但我没有任何人,它应该与 Ionic 一起使用。如何为我的应用创建此模块?

【问题讨论】:

  • Google 的 CSS 加载微调器,有很多例子可以找到。对于具有多种颜色的特定情况(例如超过 4 种,否则您可以使用 div,将其设为圆形并为每个边框使用不同的颜色),这可能有点棘手,但应该是可能的。
  • 要求我们推荐一种技术或查找书籍、工具、软件库、教程或其他场外资源的问题对于 Stack Overflow 来说是题外话
  • @user2415266 一个 HTML 元素可以有多少个边框?你如何只为一个边界设置动画? :)
  • Davide,从中心使用渐变径向背景。 colorzilla.com/gradient-editor 使用easy back in out 和CSS3 Animation 关键帧旋转它。 (这是介绍 :) )对于进度 0-100% (0-360deg) 使用谷歌(SO 搜索)。有很多例子。 搜索径向进度条。
  • 四个边框:jsfiddle.net/j79psgme 但是@RokoC.Buljan 所说的渐变可以工作。

标签: javascript css ionic spinner


【解决方案1】:

好吧,既然你想要一个时间栏,我前段时间自己做了一些东西。请注意,此解决方案并不是最好的,因为存在舍入误差,这会使条形图变得稍微太长或太短,而不是根据其宽度达到精确的 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
    }
}

【讨论】:

  • 我不需要这些,我需要在游戏开始时,所以一个颜色条及其加载(当 100% 游戏失败时,它可能会触发一个事件,我需要用javascript捕捉它,我认为有一些插件可以解决这个问题,但我不认识任何人)..
  • 哦...过度阅读,抱​​歉。那么在这种情况下,您应该在 Javascript 中使用一个变量来计算时间并相应地更新 bar 元素。我很快会编辑一些代码,之前做过类似的事情。
  • 还是谢谢 :D 如果有解决方案请告诉我 :P
  • 用我前段时间自己制作的一个小游戏更新了答案。解决方案并不理想,可能会有更好的解决方案。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-09-06
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多