我有一个JavaScript视频播放器控件,我需要在用户放大视频时保持播放时间和时间总计,或者使屏幕大于1500px宽。不确定我是否应该使用媒体查询或将CSS附加到文本类的jQuery,以确保文本不会超出范围并在窗口放大或缩小时覆盖控件。
jQuery用于控制播放器图标/文字
$('document').ready(function () {
// resize on dom ready
resizePlayer();
// add window resize binding
$(window).resize(resizePlayer);
});
function resizePlayer() {
var newWidth = $('.timeline').outerHeight() * 0.25;
var containerSize = $('.timeline').width();
var textPercentage = 0.57391304347826086956521739130435; /* 40/230 */
var textRatio = containerSize * textPercentage;
var textEms = textRatio / 244;
$('.play, .pause, .mute, .fullscreen').width(newWidth);
$('.time-played, .timeline, .time-total').css('fontSize', textEms+"em");
}
CSS
body {
background-color: #000;
}
.video-controls {
position: absolute;
background: #fff;
z-index: 2147483647;/*has to be here for full screen*/
/* default min-height */
height: 12%;
bottom: 0;
left: 0;
right: 0;
margin: auto;
min-width:500px;
}
.video-controls .container-fluid {
position: relative;
left: auto;
top: 50%;
margin-top: -14px;
height: 28px;
line-height: 28px;
width: inherit;
}
/* button & button alignments */
.video-controls .btn {
padding: 0;
border: 0;
max-width: 100%;
height: 100%;
background-color: transparent;
text-indent: 200%;
white-space: nowrap;
overflow: hidden;
vertical-align: top;
outline: 0;
cursor
}
.video-controls .btn-group-right {
position: absolute;
top: -2px;
right: -106px;
height: 100%;
}
.play {
position: absolute;
left: -73px;
top:-2px;
background: url(https://cdn4.iconfinder.com/data/icons/ionicons/512/icon-play-128.png) 50% 50% no-repeat;
/* 14 x 19 */
background-size: 17px 16px;
width: 14px;
}
.pause {
position: absolute;
left: -73px;
top:-2px;
background: url(/testPlayer/img/pause.svg) 50% 50% no-repeat;
/* 14 x 19 */
background-size: 17px 16px;
width: 14px;
}
.mute {
background: url(http://iconizer.net/files/Token/orig/Sound.png) 50% 50% no-repeat;
right: 55px;
background-size: 17px 16px;
/* 26 x 24 */
width: 26px;
}
.fullscreen {
background: url(https://cdn3.iconfinder.com/data/icons/interface/100/make_bigger_fullscreen_1-512.png) 50% 50% no-repeat;
right: 15px;
background-size: 17px 14px;
width: 24px;
/* 24 x 19 */
}
.timeline {
position: relative;
height: 100%;
width: 55%;
margin: 0 auto;
color:#fff;
}
.timeline input {
margin-top: -1px;
}
.timeline .time-total {
position: absolute;
top: 39%;
right: -47px;
font-size:14px;
color: #000;
}
.timeline .time-played {
position: absolute;
top: 39%;
left: -37px;
font-size:14px;
color: #000;
}
.timeline-progress, .timeline-total {
height: 1px;
position: absolute;
top: 50%;
left: 0;
}
.timeline-total {
width: 100%;
/*background: rgba(255,255,255,.22);*/
z-index: 1;
}
.timeline-progress {
width: 24%;
background: #fff;
z-index: 2;
}
这是一个小提琴,例如:jsfiddle
答案 0 :(得分:0)
您正在使用此js:
按比例更改字体大小$('.time-played, .timeline, .time-total').css('fontSize', textEms+"em");
但包含不会改变其大小或位置。如果删除此行代码,您将看到时间保持不变但不会更改大小。如果使用此脚本更改字体大小非常重要,则还需要调整div的位置。