1.内置对象
// 1.ecm Number Date RegExp Error XMLHttpRequest
// 2.dom querySelect MouseEvent
// 3.bom promise localstorage location cookie
// 4. 案列
let num5:Number = new Number(1)
let date:Date = new Date()
let reg:RegExp = new RegExp(/\w/)
let error:Error = new Error('错了')
let xhr:XMLHttpRequest = new XMLHttpRequest()
// HTML(元素名称)Element
let div:NodeListOf<HTMLDivElement | HTMLElement> = document.querySelectorAll('div footer')
//window
let local: Storage = localStorage
let lo: Location = location
let promise: Promise<string> = new Promise((resolve) => resolve('鹤鸣'))
promise.then((res) => {
})
let cookie: string = document.cookie
2.案例代码雨
TS部分
let canvas: HTMLCanvasElement | any = document.querySelector('canvas')
let ctx = canvas.getContext('2d')
canvas.width = screen.availWidth
canvas.height = screen.availHeight
let str: string[] = "HEMING010203".split('')
let Arr = Array(Math.ceil(canvas.width / 10)).fill(0)
const rain = () => {
ctx.fillStyle = "rgba(0,0,0,0.05)"
ctx.fillRect(0, 0, canvas.width, canvas.height)
ctx.fillStyle = '#0f0'
Arr.forEach((item, index) => {
ctx.fillText(str[Math.floor(Math.random() * str.length)], index * 10, item + 10)
Arr[index] = item > canvas.height || item > 10000 * Math.random() ? 0 : item + 10
})
}
setInterval(rain, 40)
HTML 部分
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Title</title>
<style>
* {
margin: 0;
padding: 0;
overflow: hidden;
}
</style>
</head>
<body>
<canvas id="canvas"></canvas>
<script src="./index.js"></script>
</body>
</html>