js模拟进度条

<html>
   <head>
     <style>
<!--
#bar, #barbackground{
position:absolute;
left:0;
top:0;
background-color:blue;
}

#barbackground{
background-color:black;
}

-->
</style>

<script language="JavaScript1.2">

/*
Dynamic Progress Bar- By Dynamicdrive.com
For full source, Terms of service, and 100s DTHML scripts
Visit http://www.dynamicdrive.com
*/

//1) Set the duration for the progress bar to complete loading (in seconds)
var duration=5

//2) Set post action to carry out inside function below:
function postaction(){
//Example action could be to navigate to a URL, like following:
//window.location="http://www.dynamicdrive.com"
}


///Done Editing/
var clipright=0
var widthIE=0
var widthNS=0

function initializebar(){
if (document.all){
baranchor.style.visibility="visible"
widthIE=bar.style.pixelWidth
startIE=setInterval("increaseIE()",50)
}
if (document.layers){
widthNS=document.baranchorNS.document.barbackgroundNS.clip.width
document.baranchorNS.document.barNS.clip.right=0
document.baranchorNS.visibility="show"

startNS=setInterval("increaseNS()",50)
}
}

function increaseIE(){
bar.style.clip="rect(0 "+clipright+" auto 0)"
window.status="Loading..."
if (clipright<widthIE)
clipright=clipright+(widthIE/(duration*20))
else{
window.status=''
clearInterval(startIE)
postaction()
}
}

function increaseNS(){
if (clipright<202){
window.status="Loading..."
document.baranchorNS.document.barNS.clip.right=clipright
clipright=clipright+(widthNS/(duration*20))
}
else{
window.status=''
clearInterval(startNS)
postaction()
}
}


window.οnlοad=initializebar
</script>
   </head>
   <body style="font-size:10.5pt">
    <script language="JavaScript1.2">
if (document.all){
document.write('<div id="baranchor" style="position:relative;width:200px;height:20px;visibility:hidden;">')
document.write('<div id="barbackground" style="width:200px;height:20px;z-index:9"></div>')
document.write('<div id="bar" style="width:200px;height:20px;z-index:10"></div>')
document.write('</div>')
}

</script>
<ilayer name="baranchorNS" visibility="hide" width=200 height=20>
<layer name="barbackgroundNS" bgcolor=black width=200 height=20 z-index=10 left=0 top=0></layer>
<layer name="barNS" bgcolor=blue width=200 height=20 z-index=11 left=0 top=0></layer>
</ilayer>
</body>
</html>

 来自http://www.aspxboy.com/myjs/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要实现微信小程序video组件的进度条可拖拽功能,可以使用以下步骤: 1. 在.wxml文件中,使用video组件,并加上一个view容器作为进度条的背景,再加上一个view作为进度条的滑块,代码如下: ```html <video src="{{src}}" poster="{{poster}}" bindtimeupdate="timeUpdate"></video> <view class="progress-bar"> <view class="progress" style="width: {{progress}}%;"></view> <view class="progress-btn" style="left: {{btnLeft}}px;"></view> </view> ``` 2. 在.wxss文件中,设置进度条和滑块的样式: ```css .progress-bar { position: relative; height: 6px; background-color: #ddd; } .progress { position: absolute; top: 0; left: 0; height: 6px; background-color: #f00; } .progress-btn { position: absolute; top: -5px; left: 0; width: 10px; height: 16px; border-radius: 50%; background-color: #fff; border: 2px solid #f00; box-shadow: 0 0 2px #f00; transform: translateX(-50%); } ``` 3. 在.js文件中,定义一个data对象,包含视频的总时长、当前播放时间、进度条长度和滑块位置等信息: ```javascript data: { src: 'http://www.example.com/video.mp4', poster: 'http://www.example.com/poster.jpg', duration: 0, currentTime: 0, progress: 0, btnLeft: 0, } ``` 4. 在onLoad生命周期函数中,获取视频的总时长: ```javascript onLoad: function() { var that = this; wx.createVideoContext('myVideo', that).requestFullScreen(); wx.createVideoContext('myVideo', that).play(); wx.createVideoContext('myVideo', that).pause(); wx.createVideoContext('myVideo', that).seek(0); wx.createVideoContext('myVideo', that).play(); wx.createVideoContext('myVideo', that).on('loadedmetadata', function(res) { that.setData({ duration: res.duration }); }); }, ``` 5. 在timeUpdate事件回调函数中,更新当前播放时间和进度条长度以及滑块位置: ```javascript timeUpdate: function(e) { var that = this; var currentTime = e.detail.currentTime; var duration = that.data.duration; var progress = Math.floor(currentTime / duration * 100); var btnLeft = progress * 3.4 - 7; that.setData({ currentTime: currentTime, progress: progress, btnLeft: btnLeft }); }, ``` 6. 在进度条的view容器上,绑定touchstart、touchmove和touchend事件,实现滑动改变进度条长度和滑块位置: ```javascript touchstart: function(e) { var that = this; that.setData({ startX: e.touches[0].pageX, }); }, touchmove: function(e) { var that = this; var startX = that.data.startX; var moveX = e.touches[0].pageX; var distance = moveX - startX; var duration = that.data.duration; var progress = that.data.progress + distance / 340 * 100; if (progress < 0) { progress = 0; } else if (progress > 100) { progress = 100; } var currentTime = progress / 100 * duration; var btnLeft = progress * 3.4 - 7; that.setData({ progress: progress, currentTime: currentTime, btnLeft: btnLeft, startX: moveX, }); }, touchend: function(e) { var that = this; wx.createVideoContext('myVideo', that).seek(that.data.currentTime); }, ``` 通过以上步骤,就可以实现微信小程序video组件的进度条可拖拽功能。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值