-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
440 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* 键盘按下 | ||
*/ | ||
|
||
(function() { | ||
window.addEventListener('keydown', (e: KeyboardEvent) => { | ||
console.log('keydown', e); | ||
}); | ||
|
||
window.addEventListener('keyup', e => { | ||
// console.log('keyup', e); | ||
}); | ||
|
||
window.addEventListener('keypress', e => { | ||
// console.log('keypress', e); | ||
}); | ||
}()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Keydown</title> | ||
</head> | ||
<body> | ||
<script type="module" src="./15-keydown.ts"></script> | ||
</body> | ||
</html> |
This file was deleted.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
body { | ||
background-color: #f5f5f5; | ||
background-color: #fff; | ||
margin: 0; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/** | ||
* @author 素燕(我有个公众号:素燕) | ||
* @description defs 只定义图形,不显示 | ||
*/ | ||
|
||
import { createSvg, namespace } from './helper'; | ||
|
||
(function () { | ||
const titleEl = document.getElementById('title'); | ||
titleEl.textContent = '图形-defs'; | ||
const parentEl = document.getElementById('content'); | ||
|
||
// 创建一个svg | ||
const svg = createSvg(); | ||
|
||
const defsEl = document.createElementNS(namespace, 'defs') as SVGDefsElement; | ||
|
||
const gEl = document.createElementNS(namespace, 'g') as SVGGElement; | ||
gEl.setAttribute('id', 'suyan'); | ||
gEl.style.stroke = 'red'; | ||
|
||
const lineEl = document.createElementNS(namespace, 'line') as SVGLineElement; | ||
lineEl.setAttribute('x1', '10'); | ||
lineEl.setAttribute('y1', '20'); | ||
lineEl.setAttribute('x2', '500'); | ||
lineEl.setAttribute('y2', '20'); | ||
gEl.appendChild(lineEl); | ||
|
||
let circleEl = document.createElementNS(namespace, 'circle') as SVGCircleElement; | ||
// 指定圆形和半径 | ||
circleEl.setAttribute('cx', '100'); | ||
circleEl.setAttribute('cy', '100'); | ||
circleEl.setAttribute('r', '50'); | ||
gEl.appendChild(circleEl); | ||
|
||
defsEl.appendChild(gEl); | ||
|
||
svg.appendChild(defsEl); | ||
|
||
// use 使用定义好的元素 | ||
let useEl = document.createElementNS(namespace, 'use') as SVGUseElement; | ||
useEl.setAttribute('xlink:href', '#suyan'); | ||
useEl.setAttribute('x', '10'); | ||
useEl.setAttribute('y', '200'); | ||
useEl.setAttribute('width', '200'); | ||
useEl.setAttribute('height', '100'); | ||
svg.appendChild(useEl); | ||
|
||
parentEl.appendChild(svg); | ||
|
||
}()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/** | ||
* @author 素燕(我有个公众号:素燕) | ||
* @description SVG中使用图片 | ||
*/ | ||
|
||
import { createSvg, namespace } from './helper'; | ||
|
||
(function () { | ||
const titleEl = document.getElementById('title'); | ||
titleEl.textContent = '图形-椭圆'; | ||
const parentEl = document.getElementById('content'); | ||
|
||
// 创建一个svg | ||
const svg = createSvg(); | ||
|
||
let imageEl = document.createElementNS(namespace, 'image') as SVGImageElement; | ||
imageEl.setAttribute('xlink:href', 'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fp5.itc.cn%2Fq_70%2Fimages03%2F20210621%2Fed3b6de5f476478e93cae9ab4deb4a62.jpeg&refer=http%3A%2F%2Fp5.itc.cn&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1650500871&t=bd07ba8a48aed12ba5620341c5ce9f33'); | ||
imageEl.setAttribute('x', '20'); | ||
imageEl.setAttribute('y', '20'); | ||
imageEl.setAttribute('width', '200'); | ||
imageEl.setAttribute('height', '200'); | ||
svg.appendChild(imageEl); | ||
|
||
|
||
parentEl.appendChild(svg); | ||
|
||
}()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** | ||
* @author 素燕(我有个公众号:素燕) | ||
* @description 定义图形进行复用 | ||
*/ | ||
|
||
import { createSvg, namespace } from './helper'; | ||
|
||
(function () { | ||
const titleEl = document.getElementById('title'); | ||
titleEl.textContent = '图形-symbol'; | ||
const parentEl = document.getElementById('content'); | ||
|
||
// 创建一个svg | ||
const svg = createSvg(); | ||
|
||
parentEl.appendChild(svg); | ||
|
||
}()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/** | ||
* @author 素燕(我有个公众号:素燕) | ||
* @description SVG文本 | ||
* SVGTextElement -> SVGTextPositioningElement -> SVGTextContentElement -> SVGGraphicsElement | ||
*/ | ||
|
||
import { createSvg, namespace } from './helper'; | ||
|
||
(function () { | ||
const titleEl = document.getElementById('title'); | ||
titleEl.textContent = 'text文本'; | ||
const parentEl = document.getElementById('content'); | ||
|
||
// 创建一个svg | ||
const svg = createSvg(); | ||
|
||
/** | ||
* text 和 canvas 一样,无法自动换行 | ||
*/ | ||
const textEl = document.createElementNS(namespace, 'text') as SVGTextElement; | ||
// 通过 setAttribute 来设置 text 的属性 | ||
textEl.setAttribute('x', '0'); | ||
textEl.setAttribute('y', '100'); | ||
// textEl.setAttribute('width', '10'); | ||
// textEl.setAttribute('height', '50'); | ||
// 设置字体颜色 | ||
textEl.setAttribute('fill', '#222'); | ||
|
||
// 通过 style 来设置样式 | ||
textEl.style.fontSize = '30px'; | ||
textEl.style.fontFamily = 'monospace'; | ||
textEl.style.fontWeight = '700'; | ||
textEl.style.fontStyle = 'italic'; | ||
textEl.style.textDecoration = 'underline'; | ||
textEl.style.wordSpacing = '10'; | ||
textEl.style.letterSpacing = '10'; | ||
// 对齐方式 | ||
textEl.style.textAnchor = 'start'; | ||
textEl.textContent = 'SVG是矢量图,不管你缩放多大'; | ||
|
||
// tspan如同span,把内容拆分开,单独设置属性 | ||
let tspanEl = document.createElementNS(namespace, 'tspan'); | ||
tspanEl.textContent = 'tspan内容啥效果'; | ||
textEl.appendChild(tspanEl); | ||
|
||
svg.appendChild(textEl); | ||
|
||
parentEl.appendChild(svg); | ||
|
||
}()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/** | ||
* @author 素燕(我有个公众号:素燕) | ||
* @description SVG圆形 | ||
*/ | ||
|
||
import { createSvg, namespace } from './helper'; | ||
|
||
(function () { | ||
const titleEl = document.getElementById('title'); | ||
titleEl.textContent = '图形-圆'; | ||
const parentEl = document.getElementById('content'); | ||
|
||
// 创建一个svg | ||
const svg = createSvg(); | ||
|
||
let circleEl = document.createElementNS(namespace, 'circle') as SVGCircleElement; | ||
// 指定圆形和半径 | ||
circleEl.setAttribute('cx', '100'); | ||
circleEl.setAttribute('cy', '100'); | ||
circleEl.setAttribute('r', '50'); | ||
svg.appendChild(circleEl); | ||
|
||
const textEl = document.createElementNS(namespace, 'text') as SVGTextElement; | ||
// 通过 setAttribute 来设置 text 的属性 | ||
textEl.setAttribute('x', '85'); | ||
textEl.setAttribute('y', '110'); | ||
// 设置字体颜色 | ||
textEl.setAttribute('fill', '#fff'); | ||
textEl.style.fontSize = '30px'; | ||
textEl.textContent = '燕'; | ||
svg.appendChild(textEl); | ||
|
||
parentEl.appendChild(svg); | ||
|
||
}()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* @author 素燕(我有个公众号:素燕) | ||
* @description SVG线段 | ||
*/ | ||
|
||
import { createSvg, namespace } from './helper'; | ||
|
||
(function () { | ||
const titleEl = document.getElementById('title'); | ||
titleEl.textContent = '图形-线段'; | ||
const parentEl = document.getElementById('content'); | ||
|
||
// 创建一个svg | ||
const svg = createSvg(); | ||
|
||
const lineEl = document.createElementNS(namespace, 'line') as SVGLineElement; | ||
// 设置两个点 | ||
lineEl.setAttribute('x1', '10'); | ||
lineEl.setAttribute('y1', '20'); | ||
lineEl.setAttribute('x2', '500'); | ||
lineEl.setAttribute('y2', '20'); | ||
|
||
lineEl.style.stroke = '#222'; | ||
lineEl.style.strokeWidth = '20'; | ||
lineEl.style.strokeOpacity = '0.8'; | ||
lineEl.style.strokeDasharray = '10' | ||
|
||
svg.appendChild(lineEl); | ||
|
||
parentEl.appendChild(svg); | ||
|
||
}()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** | ||
* @author 素燕(我有个公众号:素燕) | ||
* @description SVG矩形 | ||
*/ | ||
|
||
import { createSvg, namespace } from './helper'; | ||
|
||
(function () { | ||
const titleEl = document.getElementById('title'); | ||
titleEl.textContent = '图形-矩形'; | ||
const parentEl = document.getElementById('content'); | ||
|
||
// 创建一个svg | ||
const svg = createSvg(); | ||
|
||
const rectEl1 = document.createElementNS(namespace, 'rect') as SVGRectElement; | ||
rectEl1.setAttribute('x', '10'); | ||
rectEl1.setAttribute('y', '20'); | ||
rectEl1.setAttribute('width', '200'); | ||
rectEl1.setAttribute('height', '150'); | ||
// 设置圆角 | ||
rectEl1.setAttribute('rx', '10'); | ||
rectEl1.setAttribute('ry', '20'); | ||
|
||
rectEl1.style.stroke = 'red'; | ||
rectEl1.style.strokeWidth = '4'; | ||
rectEl1.style.strokeDasharray = '2'; | ||
|
||
rectEl1.style.fill = '#999'; | ||
rectEl1.style.fillOpacity = '0.6'; | ||
|
||
svg.appendChild(rectEl1); | ||
|
||
parentEl.appendChild(svg); | ||
|
||
}()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/** | ||
* @author 素燕(我有个公众号:素燕) | ||
* @description SVG椭圆 | ||
*/ | ||
|
||
import { createSvg, namespace } from './helper'; | ||
|
||
(function () { | ||
const titleEl = document.getElementById('title'); | ||
titleEl.textContent = '图形-椭圆'; | ||
const parentEl = document.getElementById('content'); | ||
|
||
// 创建一个svg | ||
const svg = createSvg(); | ||
|
||
let ellipseEl = document.createElementNS(namespace, 'ellipse') as SVGEllipseElement; | ||
// 圆形x | ||
ellipseEl.setAttribute('cx', '100'); | ||
// 圆形y | ||
ellipseEl.setAttribute('cy', '100'); | ||
// x轴的半径 | ||
ellipseEl.setAttribute('rx', '80'); | ||
// y轴的半径 | ||
ellipseEl.setAttribute('ry', '50'); | ||
svg.appendChild(ellipseEl); | ||
|
||
parentEl.appendChild(svg); | ||
|
||
}()); |
Oops, something went wrong.