$(
'.qtuploader__items'
).on(
'click'
,
'[name="viewVideoPicBtn"]'
,
function
() {
var
parent = $(this).closest(
'.qtab__page'
);
var
video = $(this).closest(
'.qtuploader__itemsbd'
).find(
'video'
);
var
srcStr =
''
, htmlStr =
''
;
if
($(this).siblings(
'.qtuploader__picinputbox'
).hasClass(
'is-error'
)){
$.fn.toast({
'parentDom'
: parent,
'classes'
:
'isorange'
,
'top'
:
'0'
,
'spacing'
: 0,
'toastContent'
:
'请设置正确范围的海报帧'
,
'autoHide'
: 3000,
'position'
: {
'top'
:
'5px'
,
'left'
:
'50%'
}
});
return
;
}
if
(video.length > 0) {
var
thumbHeight = setSize(video)[0];
var
thumbWidth = setSize(video)[1];
srcStr = video.attr(
'src'
);
htmlStr =
'<p class="qtuploader__view"><p class="qtuploader__mask"></p><p class="qtuploader__thumb" style="width:'
+ thumbWidth +
'px;height:'
+ thumbHeight +
'px;margin:0 auto;"><video controls width="'
+ thumbWidth +
'" height="'
+ thumbHeight +
'" src="'
+ srcStr +
'">您的浏览器不支持 video 标签</video></p></p>'
;
}
parent.append(htmlStr);
parent.find(
'.qtuploader__view video'
)[0].currentTime = $(this).siblings(
'.qtuploader__picinputbox'
).find(
'.qtuploader__picinput'
).val();
parent.find(
'.qtuploader__view'
).fadeIn();
});
$(
'.qtuploader__items'
).on(
'keyup'
,
'.qtuploader__picinput'
,
function
() {
var
parent = $(this).closest(
'.qtuploader__picinputbox'
);
var
video = $(this).closest(
'.qtuploader__itemsbd'
).find(
'video'
);
var
strVal
= $.trim($(this).val());
console.log(
strVal
)
if
(
strVal
==
''
) {
parent.addClass(
'is-error'
);
parent.find(
'.qverify__font'
).text(
'请设置海报帧'
);
}
else
if
(!(/^[0-9]*$/.test(
strVal
))) {
parent.addClass(
'is-error'
);
parent.find(
'.qverify__font'
).text(
'请输入数字'
);
}
else
if
(video.length > 0 &&
strVal
> video[0].duration) {
parent.addClass(
'is-error'
);
parent.find(
'.qverify__font'
).text(
'不超过('
+ video[0].duration +
')'
);
console.log(
'111---'
+ video[0].duration)
}
else
{
parent.removeClass(
'is-error'
);
parent.find(
'.qverify__font'
).text(
'请设置海报帧'
);
}
})
$(document).undelegate(
'.qtuploader__mask'
,
'click'
);
$(document).delegate(
'.qtuploader__mask'
,
'click'
,
function
() {
$(this).closest(
'.qtuploader__view'
).fadeOut(
'normal'
,
function
() {
$(this).closest(
'.qtuploader__view'
).remove();
})
})
function
setSize(element) {
var
thumbWidth = 0, thumbHeight = 0, arr = [];
var
winWidth = $(window).width(), winHeight = $(window).height();
var
imgWidth = element.width(), imgHeight = element.height();
if
(imgWidth > imgHeight) {
thumbHeight = parseInt(winHeight - 200);
thumbWidth = parseInt((1920 * thumbHeight) / 1080);
}
else
{
thumbHeight = parseInt(winHeight - 200);
thumbWidth = parseInt((1080 * thumbHeight) / 1920);
}
arr.push(thumbHeight, thumbWidth)
return
arr;
}