try{}catch{}语句+选择进度条时间
chooseVideoTime: function (event) {
try {
var currentClientX = event.clientX
var distance = currentClientX - this.progressBarOffsetLeft // 在进度条上选中的距离
if (distance < 0) return
this.player.currentTime =
(distance / this.progressBarLength) *
this.videoTotalTime
if (!this.isPlaying) {
this.player.play()
this.isPlaying = true
}
$(window).scrollTop(0);//解决ios页面被键盘顶起后,下不来的问题
// 设置当前选中时间: 进度/总长度*视频时长
} catch (error) {}
}
try语句包含了由一个或者多个语句组成的try块, 和至少一个catch块或者一个finally块的其中一个,或者两个兼有, 下面是三种形式的try声明:
try...catch
try...finally
try...catch...finally
catch子句包含try块中抛出异常时要执行的语句。也就是,你想让try语句中的内容成功, 如果没成功,你想控制接下来发生的事情,这时你可以在catch语句中实现。 如果在try块中有任何一个语句(或者从try块中调用的函数)抛出异常,控制立即转向catch子句。如果在try块中没有异常抛出,会跳过catch子句。
finally子句在try块和catch块之后执行但是在下一个try声明之前执行。无论是否有异常抛出或捕获它总是执行。
你可以嵌套一个或者更多的try语句。如果内部的try语句没有catch子句,那么将会进入包裹它的try语句的catch子句。
你也可以用try语句去处理 JavaScript 异常。