创建可点击的进度条
我本质上构建的是一个基于 webkit 的控制器,它与一个名为 Ecoute.app 的程序进行通信。
控制器有一个进度条,指示当前播放歌曲的进度,但我想通过单击来调整该进度条的位置。
function barClick() {
var progress = Ecoute.playerPosition();
var width = 142.5;
var percentElapsed = progress / length;
var position = width * percentElapsed;
Ecoute.setPlayerPosition(position);
}
这就是我所拥有的,Ecoute.playerPosition()
返回玩家的当前位置。
宽度先前被定义为动态值,
var width = 142.5 / length * progress + 1.63;
其中长度是当前轨道长度,进度是玩家的位置。这已经能够动态拉伸进度覆盖图像以通过桌面控制器指示轨道的位置。
但是,第二个函数中使用的最大宽度似乎不允许第一个函数正常工作。
任何可能确定正确值或方法的帮助将不胜感激。
What I'm essentially building is a webkit based controller that communicates with a program called Ecoute.app.
The controller has a progressbar that indicates the progress made through the currently playing song, but I want to make this bar's position adjustable with a click.
function barClick() {
var progress = Ecoute.playerPosition();
var width = 142.5;
var percentElapsed = progress / length;
var position = width * percentElapsed;
Ecoute.setPlayerPosition(position);
}
Is what I have, with Ecoute.playerPosition()
returning the player's current position.
Width has previously been defined as a dynamic value at
var width = 142.5 / length * progress + 1.63;
With length being the current track length and progress being the player's position. This has been able to dynamically stretch a progression overlay image to indicate the position of the track via the desktop controller.
However, the max width used in the second function does not appear to allow the first function to work properly.
Any help possibly determining the correct value or approach would be hugely appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
很难真正知道自己被困在哪里。我的猜测是您在使点击正常工作并确定在哪里设置进度时遇到问题。
我的解决方案是有 2 个元素,一个包裹另一个。外部元素接受单击事件,并且内部元素反映大小。您必须自己完成与 Ecoute 播放器集成的工作,但我展示了如何计算百分比。
我没有打扰任何跨浏览器工作,因为这是一个基于 webkit 的应用程序。
演示:http://jsbin.com/ubana3/5
It is hard to really know where you are getting stuck. My guess is you are having problems getting the click to work and determining where to set the progress.
My solution is to have 2 elements, one wrapping the other. The outer element takes the click event and the size gets reflected by the inner element. You will have to do your own work integrating with the Ecoute player but I showed how to calculate the percentage.
I didn't bother with any cross browser work since this is for a webkit based application.
Demo: http://jsbin.com/ubana3/5
在您的 HTML 中,
0% 已玩< /进度>
在 JQuery 中,
In your HTML,
0% played< /progress>
In JQuery,