注意:记得打开flash 打开flash方法
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link href="https://cdnjs.cloudflare.com/ajax/libs/video.js/5.3.0/video-js.min.css" rel="stylesheet">
<script src="https://cdnjs.cloudflare.com/ajax/libs/video.js/5.3.0/video.min.js"></script>
<title>视频放大镜</title>
<style>
html,body{
padding: 0;
margin: 0;
}
.con{
position: relative;
width: 400px;
height: 300px;
background-color:aquamarine;
overflow: hidden;
}
.mover{
display: none;
position: absolute;
top: 0;
left: 0;
width: 100px;
height: 75px;
border:1px solid red;
cursor: pointer;
background-color: rgba(255,255,255,.2)
}
.adddel{
position: absolute;
left: 0;
bottom: 0px;
display: flex;
justify-content:space-between;
width: 100%;
}
.adddel div{
cursor: pointer;
margin: 4px 10px;
}
.conshow{
margin-top: 10px;
display: none;
position: relative;
width: 400px;
height: 300px;
overflow: hidden;
background-color: aquamarine
}
.videocon{
position: absolute;
top: 0;
left: 0;
background-color: red
}
</style>
</head>
<body>
<div class="con">
<video id="example_video_1" class="video-js vjs-default-skin" controls preload="none" style="width: 100%;height:100%"
poster="http://vjs.zencdn.net/v/oceans.png">
<source src="rtmp://58.200.131.2:1935/livetv/hunantv" type="rtmp/flv">
</video>
<div class="mover">
<div class="adddel">
<div class="add">add</div>
<div class="reduce">reduce</div>
</div>
</div>
</div>
<div class="conshow"><div class="videocon"></div></div>
<script>
var player = videojs('example_video_1',{})
player.play();
var _videoStr = `<video id="example_video_2" class="video-js vjs-default-skin" preload="none"
style="width:100%;height:100%;"
poster="http://vjs.zencdn.net/v/oceans.png">
<source src="rtmp://58.200.131.2:1935/livetv/hunantv" type="rtmp/flv">
</video>`
var con = document.querySelector('.con');
var mover = document.querySelector('.mover');
var conshow = document.querySelector('.conshow');
var videocon = document.querySelector('.videocon');
var add = document.querySelector('.add');
var reduce = document.querySelector('.reduce');
// 倍率 con/mover
var w_dynameter,h_dynameter;
add.onclick = function(){
var _movW = mover.offsetWidth-2;
var _movH = mover.offsetHeight-2;
var _wh = _movW/_movH;
console.log(_movH*_wh)
mover.style.width = _movW + 10*_wh +2 +'px';
mover.style.height = _movH + 10 +2 +'px';
}
reduce.onclick = function(){
var _movW = mover.offsetWidth-2;
var _movH = mover.offsetHeight-2;
var _wh = _movW/_movH;
mover.style.width = _movW - 10*_wh +2 +'px';
mover.style.height = _movH - 10 +2 +'px';
}
var player2;
con.onmouseover = function(){
mover.style.display = 'block'
w_dynameter = con.offsetWidth/(mover.offsetWidth-2)//去掉边框
h_dynameter = con.offsetHeight/(mover.offsetHeight-2)
}
con.onmouseout = function(){
mover.style.display = 'none'
}
moverCon()
function moverCon(){ //mover在con拖动
var _move = false;
var _x,_y,_top,_left;
mover.onmousehover = function(){
conshow.style.display = 'none'
}
mover.onmousedown = function(down){
_move = true;
mover.style.cursor = 'move';
_x = down.clientX;
_y = down.clientY;
_top = mover.offsetTop;
_left = mover.offsetLeft;
}
mover.onmousemove = function(move){
if(_move){
var mov_top = move.clientY - _y + _top;
var mov_left = move.clientX - _x + _left
if(mov_top <=0){
mov_top = 0
}
var _htop = con.offsetHeight-mover.offsetHeight
if(mov_top >= _htop){
mov_top = _htop
}
if(mov_left <=0){
mov_left = 0
}
var _wleft = con.offsetWidth-mover.offsetWidth
if(mov_left >=_wleft){
mov_left = _wleft
}
mover.style.top = mov_top +'px';
mover.style.left = mov_left +'px';
// var _video2 = document.querySelector('#example_video_2');
videocon.style.top = -mov_top*h_dynameter+'px';
videocon.style.left = -mov_left*w_dynameter+'px';
}
}
mover.onmouseup = function(up){
_move = false;
mover.style.cursor = 'auto';
_top = up.offsetTop;
_left = up.offsetLeft;
}
mover.onmouseover = function(over){
conshow.style.display = 'block'
var _conshowW = conshow.clientWidth;
var _conshowH = conshow.clientHeight;
videocon.innerHTML = _videoStr;
player2 = videojs('example_video_2',{})
player2.play();
videocon.style.width = _conshowW*w_dynameter +'px';
videocon.style.height = _conshowH*h_dynameter +'px';
console.log(videocon,w_dynameter,h_dynameter)
console.log("w",_conshowW*w_dynameter,"h",_conshowH*h_dynameter)
_move = false;
mover.style.cursor = 'auto';
_top = over.offsetTop;
_left = over.offsetLeft;
}
mover.onmouseout = function(over){
player2.dispose()
videocon.innerHTML = '';
conshow.style.display = 'none'
}
}
// conshowvideo()
function createvideo(){
}
</script>
</body>
</html>
效果图
bug 2个视频不同步 如果有更好的方法 请大神指教