Skip to content

Commit e62a338

Browse files
author
梁怀刚
committed
feat: 整理笔记
1 parent 263e92d commit e62a338

File tree

2 files changed

+164
-18
lines changed

2 files changed

+164
-18
lines changed

docs/知识点/C2E分享会.md

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -207,46 +207,51 @@ Hardhat:
207207
Hardhat是一个以太坊开发环境,支持本地开发、测试和部署。
208208
使用示例:
209209
1. 初始化项目:
210+
```shell
210211
mkdir my-hardhat-project
211212
cd my-hardhat-project
212213
npm init -y
213214
npm instal1 --save-dev hardhat
214215
npx hardhat
216+
```
215217
2. 编写和部署智能合约:
216-
scripts/deploy. js
218+
219+
```javascript
220+
// scripts/deploy.js
217221
async function main() {
218-
const [deployer] = await ethers.getSigners();
219-
console. 1og("Deploying contracts with the account:", deployer. address);
220-
const HelloWorld
221-
await ethers.getContractFactory("HelloNorld");
222-
const helloworld = await Helloworld.deploy();
223-
console. 1og("Contract deployed to address:", helloworld.address);
222+
const [deployer] = await ethers.getSigners();
223+
console.log("Deploying contracts with the account:", deployer. address);
224+
const HelloWorld = await ethers.getContractFactory("HelloNorld");
225+
const helloworld = await Helloworld.deploy();
226+
console.log("Contract deployed to address:", helloworld.address);
224227
}
225-
main().catch((error) =>
226-
console.error (error);
227-
process.exitCode: 1;
228-
};
228+
main().catch((error) => {
229+
console.error(error);
230+
process.exitCode(1);
231+
});
232+
```
229233
3.运行部署脚本:
234+
```shell
230235
npx hardhat run scripts/deploy. js
236+
```
231237
MetaMask:
232238
MetaMask是一个浏览器插件钱包,用于与以太坊DApp交互。
233239
。安装插件后,创建或导入钱包,连接到测试网络进行开发测试。
234240
智能合约开发的基本步骤
235241
1. 编写智能合约:
236242
。使用Solidity编写合约代码。
237243
。编译合约并生成ABI(应用程序二进制接口),
238-
2. 部署合约:
244+
1. 部署合约:
239245
。使用工具(如Remix、Hardhat)将合约部署到以太坊网络(测试网或主网)
240246
。获得合约地址。
241-
3. 与合约交互:
247+
1. 与合约交互:
242248
使用Web3.s与合约进行交互,例如调用合约方法、查询状态等。
243249
示例代码:
244250
```javascript
245-
const contractABI =
246-
/* ABI数组*/];
247-
const contractAddress ='OxYourContractAddress'
248-
const contract = new web3.eth. Contract(contractABI, contractAddress);
249-
contract. methods.greeting().cal1(). then(console.1og);
251+
const contractABI = [/* ABI数组*/];
252+
const contractAddress ='OxYourContractAddress';
253+
const contract = new web3.eth.Contract(contractABI, contractAddress);
254+
contract. methods.greeting().call().then(console.1og);
250255
```
251256
总结
252257
回顾关键点:智能合约的定义、Solidity编程、工具使用和开发步骡。
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
2+
## 处理图片加载
3+
4+
1. 懒加载
5+
2. 响应式图片自动匹配尺寸
6+
7+
> https://github.com/aFarkas/lazysizes
8+
9+
## 生成图片资源
10+
11+
通过gulp生成响应式图片的方法,限于篇幅,这里只生成了90,180和360和原始图片。实际推荐生成以下宽度的图片90, 180, 360, 540, 720, 900, 1080, 1296, 1512, 1728, 2048。以便覆盖从小屏幕到大屏幕的大部分情况(包括设备分辨率为2x的情况)。
12+
13+
> *可以考虑生成32像素以下图片,用来做低分辨率的占位图
14+
15+
1.安装gulp, gulp-responsive
16+
17+
```shell
18+
yarn add --dev gulp
19+
yarn add --dev gulp-responsive
20+
```
21+
22+
2.编写 `gulpfile.js`,如下所示
23+
24+
```javascript
25+
var gulp = require('gulp')
26+
var responsive = require('gulp-responsive')
27+
gulp.task('default', function (){
28+
return gulp
29+
.src('images/*.{png, jpg}')
30+
.pipe(
31+
responsive({
32+
'*': [
33+
{
34+
width: 90,
35+
quality: 50,
36+
rename:{
37+
suffix:'-90'
38+
}
39+
},
40+
{
41+
width: 180,
42+
quality: 75,
43+
rename:{
44+
suffix:'-180'
45+
}
46+
},
47+
{
48+
width: 360,
49+
rename: {
50+
suffix:'-360'
51+
}
52+
},
53+
{
54+
rename: {
55+
suffix: '-original'
56+
}
57+
}
58+
]
59+
}, {
60+
errorOnEnlargement: false,
61+
skipOnEnlargement: true,
62+
withoutEnlargement: true
63+
})
64+
)
65+
.pipe(gulp.dest('dist/images'))
66+
})
67+
```
68+
69+
3.`npx gulp` 生成目标图片
70+
71+
## 配置使用
72+
73+
1. 初始化配置(对背景图片懒加载处理)
74+
75+
```html
76+
<script>
77+
function LoadJS(u) {
78+
var r = document.getELementsByTagName("script")[0],
79+
s = document.createElement("script");
80+
s.src = u;
81+
r.parentNode.insertBefore(s, r);
82+
}
83+
if (!window.HTMLPictureELement) {
84+
loadJS("js/ls. resp img.min.js");
85+
}
86+
</script>
87+
<script src="https://afarkas.github.io/lazysizes/plugins/bgset/ls.bgset.min.js"></script>
88+
<script src="js/lazysizes.min. js" async></script>
89+
```
90+
2. 修改图片引用
91+
92+
```html
93+
<img
94+
class="img-fluid lazyload"
95+
data-src="dist/images/p2604517782-32.jpg"
96+
data-srcset="dist/images/p2684517782-98.jpg 90w,dist/images/p2604517782-188.jpg 180w,dist/images/p2604517782-original.jpg" data-sizes="auto" alt=""
97+
>
98+
```
99+
100+
3. 对背景的引用(注意引入依赖插件)
101+
102+
```html
103+
<section
104+
class="banner lazyload"
105+
data-bgset="dist/images/sky-540.jpg 540w, dist/images/sky-1080.jpg 1080w, dist/images/sky-original.jpg"
106+
data-sizes="auto">
107+
</section>
108+
```
109+
110+
相关示例:
111+
112+
1. https://github.com/aFarkas/lazysizes
113+
2. https://jsfiddle.net/trixta/bfqqnosp/
114+
3. https://github.com/aFarkas/lazysizes/tree/e305d28d4b6c4ff9f12dd4d438d5d7c5d41574db/plugins/bgset
115+
116+
117+
## 其他注意点
118+
119+
移动设备优先: 确保适当的绘制和触屏缩放,需要在网页的 head 之中添加 viewport meta 标签,如下所示:
120+
```html
121+
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
122+
```
123+
width-device-width 表示宽度是设备屏幕的宽度。
124+
125+
initial-scale-1 表示初始的缩放比例。
126+
127+
shrink-to-fit=no 自动适应手机屏幕的宽度。
128+
129+
## 效果测试
130+
131+
### 手动测试
132+
133+
使用Chrome自带的移动端调试功能
134+
135+
### 自动测试
136+
137+
Chrome的手动测试主要在方便开发者调试,最终还是要保证在用户的真机上可以正常浏览。可以像开头图片显示的,整一些手机做测试,但是没有群控的话,测试效率过低,做群控本身工程量也不小。因此,一般推荐直接使用相关的云服务,比如BrowserStack。
138+
139+
资源链接:[BrowserStack](https://www.browserstack.com/screenshots)
140+
141+
![img](https://cdn.jsdelivr.net/gh/HarryPoint/oss@main/uPic/2024-07-24_10:57:34_LXPdQC.png)

0 commit comments

Comments
 (0)