导语: 现在基本是都做的SPA(Single page application),但是在这个之前,一般都是手动静态开发页面,下面就我之前的开发经验做一个开发总结。
# 目录
- 代码基础
- 常用工具
- 技术栈
- 常用库插件
- 适用设备
- 游览器兼容
- 打包预览
# 代码基础
本次目录结构采用腾讯前端IMWEB团队制定的代码规范。
website
└───fonts
│ │ DIN-Bold.otf
│ │ iconfont.css
│
└───images
| │ a.jpg
| │ b.jpg
| | icon.png
|
└───styles
| | reset.css
| | index.css
| | child.css
| | ie.css
|
└───scripts
| | jquery.js
| | swiper.min.js
| | index.js
| | ie.js
└───video
| | a.mp4
| index.html
| about.html
| product.html
| news.html
| contact.html
| .gitignore
| deploy.sh
│ README.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
目录文件一般使用git进行代码版本管理,每次改动可以很清晰的看到改动的地方。
# 常用工具
- 设计稿:PSCC2019
- 编辑器:vscode
- 游览器:谷歌(主),ie/360/火狐(为辅)
- http服务:live-server
- CSS/JS编译器:koala
# 技术栈
- 原生html5
- 原生css3
- 原生es6
# 常用库插件
- jquery (opens new window)主要是js的便携使用库;
- swiper (opens new window)主要是制作轮播图;
- zoomsl主要是制作图片放大镜;
- animate (opens new window)主要是css3动画;
- wow (opens new window)主要是动画特效;
# 适用设备
# pc端常用分辨率
- 17/19英寸正屏:
1280*1024
- 18.5英寸:
1366*768
- 19英寸:
1440*900
- 20英寸:
1600*900
- 21.5英寸:
1920*1080
- 22英寸:
1680*1050
- 23英寸/24英寸:
1920*1080
- 27英寸:
1920*1080/2560*1440
- 30英寸:
2560*1600
# 手机端常用分辨率
# 屏幕比
4:3
- VGA
640*480
(Video Graphics Array) - QVGA
320*240
(Quarter VGA) - HVGA
480*320
(Half-size VGA) - SVGA
800*600
(Super VGA)
- VGA
5:3
- WVGA
800*480
(Wide VGA)
- WVGA
16:9
- FWVGA
854*480
(Full Wide VGA) - HD
1920*1080
High Definition - QHD
960*540
- 720p
1280*720
标清 - 1080p
1920*1080
高清
- FWVGA
# 手机
- iphone4/4s:
960*640
(3:2) - iphone5:
1136*640
- 小米1:
854*480
(FWVGA) - 小米2:
1280*720
# 分辨率对应DPI
- "HVGA mdpi"
- "WVGA hdpi "
- "FWVGA hdpi "
- "QHD hdpi "
- "720P xhdpi"
- "1080P xxhdpi "
# 游览器兼容
# 开发步骤
- 首先使用chrome游览器进行开发;
- 针对不同设备的分辨率进行微调;
- 针对不同游览器进行微调;
# 部分代码
- 判断不同游览器
function checkBrowserName () {
let browserName = '';
if (navigator.userAgent.indexOf('Chrome') != -1) {
browserName = 'Chrome';
} else if (navigator.userAgent.indexOf('Trident') != -1 || navigator.appVersion.indexOf('MSIE') != -1) {
browserName = 'IE';
} else if (navigator.userAgent.indexOf('Firefox') != -1) {
browserName = 'Firefox';
} else if (navigator.userAgent.indexOf('Opera') != -1) {
browserName = 'Opera';
} else if (navigator.userAgent.indexOf('Safari') != -1) {
browserName = 'Safari';
}
return browserName;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15
- 判断ie游览器版本型号
// 获取ie版本
function getIeVersion() {
var ie = navigator.userAgent.indexOf('Trident') == -1 ? false : true;
var version = navigator.appVersion;
var versionName = '';
if (ie && version) {
if (version.indexOf('rv:11.0') != -1) {
return versionName = 'ie11'
} else if (version.indexOf('MSIE 10.0') != -1) {
return versionName = 'ie10'
} else if (version.indexOf('MSIE 9.0') != -1) {
return versionName = 'ie9'
} else if (version.indexOf('MSIE 8.0') != -1) {
return versionName = 'ie8'
} else if (version.indexOf('MSIE 7.0') != -1) {
return versionName = 'ie7'
}
}
return -1;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
- 统一添加页面样式
let ieVer = getIeVersion();
if (ieVer !== -1) {
document.body.className = 'ie';
document.body.id = 'ieb';
let link = document.createElement('link');
link.rel = 'stylesheet';
link.href = 'styles/ie.css';
document.head.appendChild(link);
}
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
- pc手机重定向
// simple mobile redirect
function simplePcRedirect (type) {
// type 1.二级域名 2.二级目录 3.英文二级目录
let isMobile = 'ontouchstart' in document;
let protocol = location.protocol;
let hostname = location.hostname;
let pathname = location.pathname;
let params = location.search;
let directType = type || 1;
let url = '';
if (directType == 1) {
if (isMobile) {
let host = hostname.indexOf('www') > -1 ? hostname.replace(/www/gi, '') : '.'+hostname;
url = protocol+'//m'+host+pathname+params;
location.href = url;
}
}
if (directType == 2) {
if (isMobile && location.href.indexOf('/m/') === -1) {
let url = location.origin + '/m' + location.pathname + location.search;
location.href = url;
}
}
if (directType == 3) {
if (isMobile && location.href.indexOf('/en/') > -1) {
let ph = location.pathname.slice(/en/, '');
let url = location.origin + '/en_m' + ph + location.search;
location.href = url;
}
}
}
// simple mobile redirect
function simpleMoblieRedirect (type, isWww) {
// type 1.二级域名 2.二级目录 3.英文二级目录
let isMobile = 'ontouchstart' in document;
let protocol = location.protocol;
let hostname = location.hostname;
let pathname = location.pathname;
let params = location.search;
let directType = type || 1;
if (directType == 1) {
if (!isMobile) {
let host = hostname.indexOf('m') > -1 ? hostname.replace(/m/gi, '') : hostname;
if (isWww) {
host = 'www'+host;
} else {
host = host.slice(1, host.length);
}
url = protocol+'//'+host+pathname+params;
location.href = url;
}
}
if (directType == 2) {
if (!isMobile && location.href.indexOf('/m/') > -1) {
let pathname = location.pathname.replace('/m/', '/');
let url = location.origin + pathname + location.search;
location.href = url;
}
}
if (directType == 3) {
if (!isMobile && location.href.indexOf('/en_m/') > -1) {
let ph = location.pathname.slice(/en_m/, '');
let url = location.origin + '/en' + ph + location.search;
location.href = url;
}
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
- remjs代码
function remSize() {
let regular = 16 / 1920;
let regularPhone = 100 / 750;
let windowWin = window.innerWidth;
let windowWinPhone = window.screen.width;
let rem = windowWin * regular;
let remPhone = windowWinPhone * regularPhone;
if (window.screen.width <= 768) {
document.documentElement.style.fontSize = remPhone + 'px';
} else {
document.documentElement.style.fontSize = rem + 'px';
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13
- sass rem代码
$baseFontSize: 16px;
@mixin px2rem ($name, $px) {
#{$name}: $px / $baseFontSize * 1rem;
}
@function pxToRem ($px) {
@return $px / $baseFontSize * 1rem;
}
div {
width: pxToRem(30);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13
- 移动端js动态字体
document.documentElement.style.fontSize = document.documentElement.clientWidth / 7.5 + 'px';
1
如果设计稿是750px
的,字体是16px
,那么除以就是750/16
,依此类推。
# 打包预览
优化压缩
- fonts字体压缩;字客网 (opens new window)
- 图片压缩;tinypng (opens new window)
- css压缩;vscode-plugin-minify (opens new window)
- js压缩;vscode-plugin-minify (opens new window)
- html不压缩;
预览
使用
live-server
进行预览查看,命令:
# 自定义端口号 # 语法如下 live-server --port=<port> --host=<protocal> # 示例如下 live-server --port=4001 --host=localhost
1
2
3
4
5压缩包发布
这一步骤就是针对整个网站文件进行zip/rar进行压缩,便于传输。
目前就是做一般静态页面网站的一些开发总结,以后会逐渐补充一些的。