Kev*_*vin 5 javascript jquery slider
我有一个关于在浏览器中实现滑块控件的问题.
我需要在浏览器中随时间回放数据.我将通过调用REST api让一个Worker填充回放缓冲区.然后,UI线程将使用缓冲区并将数据回放给用户.
我想模拟YouTube进度UI控件.它会在单个UI控件中显示您已观看了多少,以及预取了多少.是否可以调整滑块控件来执行此操作?jQuery UI范围滑块不是我想要的
我目前在我的网站上使用jQuery,所以更喜欢基于该框架的解决方案.
您可以使用自己的背景图像稍微修改 jQuery UI 滑块,然后调整宽度以显示加载进度(演示):
$(function(){
var ytplayer = $('#player')[0],
// # seconds from YouTube API
duration = ytplayer.getDuration(),
// # bytes
totalBytes = ytplayer.getVideoBytesTotal(),
// start # bytes - may not be necessary
startBytes = ytplayer.getVideoStartBytes();
$("#slider").slider({
range: "max",
min: startBytes,
max: duration,
value: 1
})
// image: http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/blitzer/images/ui-bg_highlight-soft_15_cc0000_1x100.png
// with a 30% opacity
.css('background-image', 'url(http://i56.tinypic.com/fbjad2.png)');
// Loop to update slider
function loop() {
var time = ytplayer.getCurrentTime(),
// make loaded a percentage
loaded = 100 - (ytplayer.getVideoBytesLoaded() / totalBytes) * 100;
// set limit - no one likes negative widths
if (loaded < 0) { loaded = 0; }
// update time on slider
$('#slider')
.slider('option', 'value', time)
.find('.ui-widget-header').css('width', loaded + '%');
// repeat loop as needed
if (loaded < 0 || time < duration) {
setTimeout(loop, 500);
}
}
loop();
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2372 次 |
| 最近记录: |