我正在使用for循环来创建缩略图对象数组,以便在进度条上显示缩略图。但它会出现“Uncaught SyntaxError:Unexpected token<”错误在for循环。为什么它会出现这个错误?
这是代码
<script>
// initialize video.js
var video = videojs('video');
// here's an example of generating thumbnails from a sprited image:
var l=40;
var t=60;
var c=0;
var tp=0;
var rt=80;
var bt=45;
var lt=0;
var i;
var j;
var op={};
video.thumbnails({
for(i=0,j=1;i<=95;i=i+5)
{
op[i]={src: 'M'+c+'.jpg',style: {left: '-'+l+'px',width: '800px',height: '90px',top: '-'+t+'px',clip: 'rect('+tp+'px,'+ rt+'px,'+ bt+'px,'+lt+ 'px)'}}
l=l+80;
rt=rt+80;
lt=lt+80;
if(j%10==0){t=t+45;rt=80;lt=0;l=40;}
if(j%100==0)
{t=60;c=c+1;
tp=0;rt=80;bt=45;lt=0;
}
j++;
}
)}
</script>
此外,我想创建像这样的缩略图对象数组。如何动态或使用循环等?
/*
0:{src: 'M0.jpg',style: {left: '-40px',width: '800px',height: '450px',top: '-60px',clip: 'rect(0, 80px, 45px, 0px)'}},
5:{src: 'M0.jpg',style: {left: '-120px',width: '800px',height: '450px',top: '-60px',clip: 'rect(0, 160px, 45px, 80px)'}},
10:{src: 'M0.jpg',style: {left: '-200px',width: '800px',height: '450px',top: '-60px',clip: 'rect(0, 240px, 45px, 160px)'}},
15:{src: 'M0.jpg',style: {left: '-280px',width: '800px',height: '450px',top: '-60px',clip: 'rect(0, 320px, 45px, 240px)'}},
20:{src: 'M0.jpg',style: {left: '-360px',width: '800px',height: '450px',top: '-60px',clip: 'rect(0, 400px, 45px, 320px)'}}*/
});*/
答案 0 :(得分:0)
我不确定这是你想要的,但是这段代码没有错误:
var video = videojs('video');
// here's an example of generating thumbnails from a sprited image:
var l = 40;
var t = 60;
var c = 0;
var tp = 0;
var rt = 80;
var bt = 45;
var lt = 0;
var i;
var j;
var op = {};
video.thumbnails((function() {
for (i = 0, j = 1; i <= 95; i = i + 5) {
op[i] = {
src: 'M' + c + '.jpg',
style: {
left: '-' + l + 'px',
width: '800px',
height: '90px',
top: '-' + t + 'px',
clip: 'rect(' + tp + 'px,' + rt + 'px,' + bt + 'px,' + lt + 'px)'
}
}
l = l + 80;
rt = rt + 80;
lt = lt + 80;
if (j % 10 == 0) {
t = t + 45;
rt = 80;
lt = 0;
l = 40;
}
if (j % 100 == 0) {
t = 60;
c = c + 1;
tp = 0;
rt = 80;
bt = 45;
lt = 0;
}
j++;
}
return op;
}()));
在你的代码中,函数缩略图收到了无效对象,你不能在对象的开头放一个for循环。