大家好,又见面了,我是你们的朋友全栈君。
缺陷:用户在控制台能直接拿到视频url地址
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0;" name="viewport" />
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<title>视频试看</title>
</head>
<style type="text/css">
*{
margin: 0;
padding: 0;
}
.videobox{
position: relative;
width: 100%;
}
.videobox video{ width: 100%; }
.zhezhao{
position: absolute;
background: #000;
width: 100%;
top: 0;
bottom: 0;
display: none;
z-index: 9;
cursor: pointer;
}
.shikanjieshu{
color: #fff;
position: absolute;
width: 100%;
top: 0;
bottom: 0;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
}
.chongxinkaishibox{
text-align: center;
font-size: 12px;
}
.chongxinkaishibox img{
width: 30px;
}
</style>
<body>
<!-- https://y1pindao.com/app/img/mp4/afd83049775b55c1f9e93132d9ff1e3f.mp4 -->
<div class="videobox">
<video src="https://y1pindao.com/app/img/mp4/afd83049775b55c1f9e93132d9ff1e3f.mp4" poster="loading.gif" controls preload="auto" id="player"></video>
<div class="zhezhao">
<div class="shikanjieshu">
<div class="chongxinkaishibox">
<img src="chongxinkaishi.png" />
<div>试看结束,点击重新开始</div>
</div>
</div>
</div>
</div>
<script type="text/javascript">
let num = 60*5;
let pl=document.getElementById("player");
pl.addEventListener("timeupdate",function(){
if(parseInt(pl.currentTime)>=num){
pl.pause()
document.getElementsByClassName('zhezhao')[0].style.display = 'block';
console.log(pl)
pl.setAttribute('src','')
}
})
document.getElementsByClassName("zhezhao")[0].addEventListener('click',function(){
console.log('重新开始')
document.getElementsByClassName('zhezhao')[0].style.display = 'none';
pl.setAttribute('src','https://y1pindao.com/app/img/mp4/afd83049775b55c1f9e93132d9ff1e3f.mp4')
pl.currentTime=0;
pl.play();
})
</script>
</body>
</html>
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/125691.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...