歌曲的进度栏 [英] Progress_bar for song

查看:119
本文介绍了歌曲的进度栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要跟随歌曲时间的progress_bar.我该如何在歌曲结束时准确地设置progress_bar的结束时间?

i need a progress_bar that follow the time of a song. how can i set the end time of progress_bar exactly in the moment when the song finish?

例如如果我的歌曲持续时间为4:38分钟,如何在此特定时间段内(从我单击到之后的4:38分钟)创建一个progress_bar?

ex. if my song has duration of 4:38 minutes how can i create a progress_bar for this specif period of time ( from when i click to 4:38 min after) ?

 var progressBar = $('#progress-bar'),
 width = 0;

 progressBar.width(width);

 var interval = setInterval(function() {
    width += 10;
    progressBar.css('width', width + '%');

    if (width >= 100) {
       clearInterval(interval);
    }
  }, 1000)

谢谢.

推荐答案

4:38是4 * 60 + 38 = 278秒,这意味着指示条应该每秒移动(1/278)* 100%

4:38 is 4 * 60 + 38 = 278 seconds, which means every second the bar should move (1/278)*100 percent

var step = 100/(minutes*60 + seconds);

var interval = setInterval(function() {
   width += step;
   progressBar.css('width', width + '%');

  if (width >= 100) {
     clearInterval(interval);
  }
}, 1000)

这篇关于歌曲的进度栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆