JS阅读笔记

myweb3.html

html 复制代码
<video id="video" width="400" height="300" autoplay></video>
<button id="capture-btn">拍摄图片</button>
<canvas id="canvas" width="400" height="300"></canvas>
<img id="photo" src="" alt="拍摄的图片">
<script>  
    const video = document.getElementById('video');
    const captureBtn = document.getElementById('capture-btn');
    const canvas = document.getElementById('canvas');
    const photo = document.getElementById('photo');

    // 获取用户媒体设备权限
    navigator.mediaDevices.getUserMedia({ video: true })
        .then(stream => {
            video.srcObject = stream;
        })
        .catch(error => {
            console.error('Error accessing media devices:', error);
        });

    // 拍摄图片
    captureBtn.addEventListener('click', () => {
        canvas.getContext('2d').drawImage(video, 0, 0, canvas.width, canvas.height);
        const imgDataUrl = canvas.toDataURL();
        photo.src = imgDataUrl;
    });
</script>
  • canvas.getContext('2d'):获取二维图像
  • canvas.toDataURL:save canvas image to url
  • drawImage(video,x,y,width,height):
  • video的属性:video/mp4/ogg/webm,simple implement:见菜鸟教程link
html 复制代码
<!DOCTYPE html> 
<html> 
<head> 
<meta charset="utf-8"> 
<title>菜鸟教程(runoob.com)</title> 
</head>
<body> 

<div style="text-align:center"> 
  <button onclick="playPause()">播放/暂停</button> 
  <button onclick="makeBig()">放大</button>
  <button onclick="makeSmall()">缩小</button>
  <button onclick="makeNormal()">普通</button>
  <br> 
  <video id="video1" width="420">
    <source src="mov_bbb.mp4" type="video/mp4">
    <source src="mov_bbb.ogg" type="video/ogg">
    您的浏览器不支持 HTML5 video 标签。
  </video>
</div> 

<script> 
var myVideo=document.getElementById("video1"); 

function playPause()
{ 
	if (myVideo.paused) 
	  myVideo.play(); 
	else 
	  myVideo.pause(); 
} 

	function makeBig()
{ 
	myVideo.width=560; 
} 

	function makeSmall()
{ 
	myVideo.width=320; 
} 

	function makeNormal()
{ 
	myVideo.width=420; 
} 
</script> 
</body> 
</html>

修改tomcat 默认打开页面

在web.xml中

xml 复制代码
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>

try it,it's found the former,

convey xml protocal in http connection

html 复制代码
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script>
function loadXMLDoc()
{
	var xmlhttp=new XMLHttpRequest();
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
		}
	}
	xmlhttp.open("GET","/try/ajax/ajax_info.txt",true);
	xmlhttp.send();
}
</script>
</head>
<body>

<div id="myDiv"><h2>使用 AJAX 修改该文本内容</h2></div>
<button type="button" onclick="loadXMLDoc()">修改内容</button>

</body>
</html>

HTML 如何显示 图片

js FileReader

https://juejin.cn/post/7028590772333051918

创建隐藏元素

  • 作用:实现中间数据在不同函数间的共享、导出
js 复制代码
const downloadPhoto = () => {
  const link = document.createElement('a');
  link.download = '你的帅照.png';
  link.href = canvas.toDataURL();
  link.click();
}
相关推荐
低头专研1 小时前
Markdown标题序号处理工具——用 C 语言实现
c语言·开发语言·typora·markdown文件标题编号·md文件标题序号
Starry_hello world1 小时前
Linux 的准备工作
linux·笔记·有问必答
程序猿John1 小时前
ES6 新增特性 箭头函数
前端·javascript·es6
@大迁世界2 小时前
彻底改变我 React 开发方式的组件模式
前端·javascript·react.js·前端框架·ecmascript
刚入门的大一新生3 小时前
C++初阶-C++入门基础
开发语言·c++
你是理想3 小时前
wait 和notify ,notifyAll,sleep
java·开发语言·jvm
William Dawson3 小时前
【Vue 3 + Element Plus 实现产品标签的动态添加、删除与回显】
前端·javascript·vue.js
拉不动的猪3 小时前
项目基础搭建时的一些基本注意点
前端·javascript·面试
IT _oA3 小时前
Active Directory 域服务
运维·服务器·网络·windows·笔记
forestsea3 小时前
Python进阶编程总结
开发语言·python·notepad++