Uncaught SyntaxError: Unexpected token < using for loop in video js thumbnail
Uncaught SyntaxError: Unexpected token < using for loop in video js thumbnail
我正在使用 for 循环创建缩略图对象数组以在进度 bar.But 上显示缩略图 bar.But 它在 for loop.Why 处给出了 "Uncaught SyntaxError: Unexpected token <" 的错误 它给出了这个错误?
这是代码
<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>
我还想创建像 this.How 这样的缩略图对象数组,我可以动态地或使用循环等来做这个吗?
/*
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)'}}*/
});*/
我不确定这是你想要的,但这段代码没有错误:
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 循环。
我正在使用 for 循环创建缩略图对象数组以在进度 bar.But 上显示缩略图 bar.But 它在 for loop.Why 处给出了 "Uncaught SyntaxError: Unexpected token <" 的错误 它给出了这个错误?
这是代码
<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>
我还想创建像 this.How 这样的缩略图对象数组,我可以动态地或使用循环等来做这个吗?
/*
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)'}}*/
});*/
我不确定这是你想要的,但这段代码没有错误:
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 循环。