video盒子下面多出了一部分

video盒子下面多出了一部分

5a70692a00015e7605000334.jpg

5a70692a00011f9c05000320.jpg

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>videoPlayer</title>
<link rel="stylesheet" type="text/css" href="css/videoPlayer.css">
<script src="https://cdn.bootcss.com/jquery/2.2.4/jquery.js"></script>
</head>
<body>
<div class="videoPlayer" id="videoPlayer">
<video id="video" src="imooc.mp4" width="600px" poster="img/potser.jpg"></video>
<!-- 头部标题 -->
<div class="caption" id="caption">myVideo</div>
<!-- 控制区 -->
<div class="control" id="control">
<!-- 控制区上面补分 -->
<div class="top">
<!-- 播放时间 -->
<span class="startTime" id="startTime">00:00</span>
<!-- 视频进度条 -->
<div class="progress">
<div class="timeBar" id="timeBar"></div>
</div>
<!-- 总时长/剩余时长 -->
<span class="endTime" id="endTime">00:00</span>
</div>
<!-- 控制区下面部份 -->
<div class="bottom">
<div class="startBtn botton" id="startBtn"></div>
<div class="endBtn botton" id="endBtn"></div>
<div class="speed1 botton" id="speed1">x1</div>
<div class="speed2 botton" id="speed2">x3</div>
<div class="valume">
<div class="valumeBar"></div>
</div>
<div class="sound botton" id="soundBtn"></div>
<div class="fullscreenBtn" id="fullscreenBtn"></div>
</div>
</div>
</div>
<script src="js/vedioPlayer.js"></script>
</body>
</html>
*{
	padding:0;
	margin:0;
}
ul{
	list-style-type: none;
}
a{
	text-decoration: none;
}
.pause{
	background: url(../img/icon/pause.png) no-repeat !important;
}
.videoPlayer{
	position: relative;
	width: 600px;
	margin:30px auto;
	overflow: hidden;
}
.videoPlayer>.caption{
	position: absolute;
	left: 0;
	top: 0;
	width: 100%;
	height: 30px;
	line-height: 30px;
	color: #fff;
	text-align: center;
	background:#1f1f1f;
}

/*控制区*/
.videoPlayer>.control{
	position: absolute;
	left: 0;
	bottom: 0;
	width: 100%;
	height: 50px;
	color: #fff;
	font-size: 12px;
	background:#1f1f1f;
}
/*控制区顶部*/
.control>.top{
	width: auto;
	height: 16px;
	line-height: 16px;
	padding: 0 1%;
	border-bottom: 1px solid #404040;
}
.control>.top>.startTime,
.control>.top>.progress{
	float: left;
}
.control>.top>.startTime,{
	width: 7%;
	text-align: center;
}
.control>.top>.progress{
	height: 12px;
	width: 86%;
	margin-top: 2px;
	margin-left: 5px;
	border-radius: 5px;
	background:#404040;
	cursor: pointer;
}
.control>.top>.progress>.timeBar{
	width: 50px;
	height: 100%;
	border-radius: 5px;
	background:rgba(255,162,68,0.8);
}
.control>.top>.endTime{
	float: right;
	text-align: center;
	width: 7%;
	cursor: pointer;
}
/*控制区底部*/
.control>.bottom{
	width: auto;
	height: 25px;
	padding:4px;
}
.control>.bottom>.botton{
	float: left;
	width: 25px;
	height: 25px;
	padding:0 3px;
	text-align: center;
	cursor: pointer;
}
.control>.bottom>.botton:nth-child(3),
.control>.bottom>.botton:nth-child(4){
	font-size: 15px;
	line-height: 25px;
	text-align: center;
}
.control>.bottom>.startBtn{
	background:url(../img/icon/play.png) no-repeat;
}
.control>.bottom>.endBtn{
	background:url(../img/icon/stop.png) no-repeat;
}
.control>.bottom>.sound,
.control>.bottom>.valume{
	float: right;
}
.control>.bottom>.sound{
	background:url(../img/icon/sound.png) no-repeat;
}
.control>.bottom>.valume{
	width: 100px;
	height: 10px;
	background:#404040;
	margin-top: 7px;
	margin-right: 4px;
	cursor: pointer;
}
.control>.bottom>.valume>.valumeBar{
	width: 10px;
	height: 100%;
	background:#ddd;
}
$(document).ready(function(){
	var player=$('#videoPlayer');
	var video=$('#video');
	var caption=$('#caption');
	var control=$('#control');
	var startBtn=$('#startBtn');
	var endTime=$('#endTime');
	var startTime=$('#startTime')
	var timeBar=$('#timeBar');
	//在元数据加载后初始化视频数据
	video.on('loadedmetadata',function(){
		//时间初始化
		endTime.text(timeFormat(video[0].duration));
		//绑定player移入移除事件
		player.hover(function(){
			//移入时显示标题和控制区
			showTitleAndControl(true);
		},function(){
			//移出时隐藏标题和控制区
			showTitleAndControl(false);
		})
		//绑定开始按钮点击事件
		startBtn.click(function(){
			//调用开始和暂停视频函数
			startAndPause();
		})
		//绑定进度条事件
		video.on('timeupdate',function(){
			var lenPercent=video[0].currentTime/video[0].duration*100;
			timeBar.css({width:lenPercent+'%'});
			startTime.text(timeFormat(video[0].currentTime))
			console.log(lenPercent)
		})
		
	})
	//视频长度时间格式化
	function timeFormat(time){
		//获取视频分钟
		minutes=Math.floor(time/60);
		//获取视频秒
		seconds=Math.floor(time%60);
		//如果是个位数,在前面加个0
		if(minutes<10){
			minutes='0'+minutes;
		}else if(seconds<10){
			seconds='0'+seconds;
		}
		//拼接完整的时间
		videoLength=minutes+':'+seconds;
		//返回格式化的时间
		return videoLength;
	}
	// 开始和暂停播放
	function startAndPause(){
		if(video[0].paused || video[0].ended){
			startBtn.addClass('pause');
			video[0].play();
		}else{
			startBtn.removeClass('pause');
			video[0].pause();
		}
	}
	//显示和隐藏标题&控制区
	function showTitleAndControl(shouldShow){
		if(shouldShow){
			caption.stop().animate({top:0},500)
			control.stop().animate({bottom:0},500)
		}else{
			caption.stop().animate({top:-30+'px'},500)
			control.stop().animate({bottom:-50+'px'},500)
		}
	}
})

如图,整个盒子的下面会多出一点,导致控制区和盒子间有留白,自己找了半天不知道原因,希望老师指导一下(代码比较多QAQ麻烦啦)

正在回答

登陆购买课程后可参与讨论,去登陆

3回答

针对新发现问题,调整如下:

  1. 指定视频容器的高度

    http://img1.sycdn.imooc.com//climg/5a71a02e0001ee6501780110.jpg

2. 指定下面控制条的top值

http://img1.sycdn.imooc.com//climg/5a71a0880001e74901990172.jpg

动手实践,加油!

  • hunmix 提问者 #1
    非常感谢,但是很遗憾还是没找到问题所在QAQ我在自己研究研究吧
    2018-01-31 21:20:31
提问者 hunmix 2018-01-31 15:33:46

http://img1.sycdn.imooc.com//climg/5a717133000195f310940580.jpg

如图,我把poster属性去掉了,而控制区上面还是有缝隙,应该不是图片引起的

小于飞飞 2018-01-31 10:49:11

你好,因为没有你代码中的素材文件,所以不好确定具体问题,根据代码和截图来看,考虑potser.jpg 这个图片的大小是否和该盒区域大小一样,所导致的问题,测试如下:高度大,宽度不足,所以下面没有空白,左右有空白。

http://img1.sycdn.imooc.com//climg/5a712e460001521006940414.jpg

在试一试,加油!

  • 提问者 hunmix #1
    确实是这个问题,感谢,还有个问题,就是poster图片大小该如何设置呢,刚才是把盒子的高度改了才达到的效果,这样结局似乎不太好
    2018-01-31 13:44:45
  • 小于飞飞 回复 提问者 hunmix #2
    给video添加样式,动手实践,如下: #video{ width: 100%; height: 100%; background: transparent url('img/1.png') 50% 50% no-repeat; /*要显示的播放前的图片 */ background-size:cover; }
    2018-01-31 14:47:28
  • 提问者 hunmix 回复 小于飞飞 #3
    我发现不是图片的问题,就算去掉了图片还是会有空隙,但是设置的是video的宽600px,高度auto,盒子的宽度600px,高度子元素撑开,不知道哪来的空隙啊QAQ以及设置背景图片并不显示啊,只有在刷新的时候会闪一下,我下回复里上图
    2018-01-31 15:31:35
问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
响应式开发与常用框架 2018
  • 参与学习           人
  • 提交作业       2198    份
  • 解答问题       5012    个

如果你有web端基础,既想进阶,又想进军移动端开发,那就来吧,我们专题为你带来的课程有HTML5、CSS3、移动基础、响应式、bootstrap、less等,让你在前端道路上畅通无阻!

了解课程
请稍等 ...
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师