js实现视频镜面反转的示例代码
作者:Postkarte不想说话
这篇文章主要为大家详细介绍了如何利用JavaScript实现视频镜面反转的效果,文中的示例代码简洁易懂,感兴趣的小伙伴可以跟随小编一起学习一下
添加下一个样式即可
#left { transform: rotateY(180deg); }
完整代码
<!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"> <title>js通过浏览器调用摄像头</title> <style> #left { transform: rotateY(180deg); } </style> </head> <body> <div class="banner"> <video id="left" width="500px" height="500px" autoPlay="autoplay" controls="controls"></video> <video id="right" width="500px" height="500px" autoPlay="autoplay" controls="controls"></video> </div> </body> <script> let leftVideo = document.getElementById('left'); let rightVideo = document.getElementById('right'); function getMedia() { let constraints = { video: { width: 400, height: 500 }, audio: false }; navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia; navigator.mediaDevices.getUserMedia( constraints, function(stream) { leftVideo.src = stream; leftVideo.play(); }, function(error) { console.log(error); } ).then(function(MediaStream) { leftVideo.srcObject = MediaStream; leftVideo.play(); }); } getMedia(); // 当开始播放的时候哦从一个video标签中获取流并将流传给其他的video标签 leftVideo.onplay = function () { rightVideo.srcObject = leftVideo.captureStream() } </script> </html>
效果图
到此这篇关于js实现视频镜面反转的示例代码的文章就介绍到这了,更多相关js视频镜面反转内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!