0%

1,建立package.json 安装gulp 和es6-babel

1
2
3
4
5
6
7
npm init
npm install --save-dev gulp
npm install --save-dev gulp-babel
npm install --save-dev babel-preset-es2015
//命令行中建立文本文件 .babelrc
$ echo '{ "presets": ["latest"] }' > .babelrc
gulp

2,gulpfile.js

1
2
3
4
5
6
7
8
var gulp = require("gulp");
var babel = require("gulp-babel");

gulp.task("default", function () {
return gulp.src("src/**/*.js")// ES6 源码存放的路径
.pipe(babel())
.pipe(gulp.dest("dist")); //转换成 ES5 存放的路径
});

https://github.com/weibsgz/vue2.0_cart
VUE2.0购物车代码下载
====================================

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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<title>Document</title>
<link rel="stylesheet" href="css/reset.css">
<link rel="stylesheet" href="css/css.css">
</head>

<body>
<div class="main" id="app">
<table class="table">
<tr>
<th></th>
<th>商品信息</th>
<th>商品金额</th>
<th>商品数量</th>
<th>总金额</th>
<th>编辑</th>
</tr>
<tr v-for="(item,index) in productListFilter">
<td>
<div class="uncheck" v-bind:class="{'checked':item.checked}" @click="selectedProduct(item)"></div>
</td>
<td>
<div class="item_img">
<img v-bind:src="item.productImage" alt="" width="150px" height="150px">
<p>{{item.productName + index}}</p>
<!-- 这里再次循环item中的数据 -->
<p>赠送:<span v-for="part in item.partsName">{{part.partsName}}</span></p>
</div>
</td>
<td>
<p>{{item.productPrice | formatMoney}}</p>
</td>
<td>
<em @click="reduce(item)"> - </em>
<!-- 双向数据绑定,绑定数量影响总价格 -->
<input type="text" style="width: 30px;" v-model="item.productQuentity">
<em @click="add(item)"> + </em>
</td>
<td>
<p class="totalCount">{{item.productPrice * item.productQuentity | money('元')}}</p>
</td>
<td>
<p class="del" @click="delProduct(index)">删除</p>
</td>
</tr>
</table>
<div class="menu">
<div class="menuLeft">
<div class="uncheck" style="display: inline-block;" :class="{'checked':checkAllFlag}" @click="checkAll()"></div>
<span style="margin-right: 15px;">全选</span><span>取消全选</span>
</div>
<div class="menuRight">
总金额<span>{{totalMoney}}</span>
<button>结算</button>
</div>
</div>


<div class="test">
<ul>
<li v-for="(item,index) in tab" :class="{'active':testIndex == index}" @click="tabChange(index)">
{{item.name}}
</li>
</ul>
<!-- 第一种方法: -->
<div class="content" >
{{tabContent[activeContentIndex].value}}
</div>

<!-- 第二种方法: -->
<!-- <div class="content" v-for="(item,index) in tabContent" v-show="stat == index">{{item.value}}</div> -->

</div>

</div>





<script type="text/javascript" src="js/vue.min.js"></script>
<script type="text/javascript" src="js/vue-resource.min.js"></script>
<script src="js/jquery-1.7.1.min.js"></script>
<script type="text/javascript">
var vm = new Vue({
el: "#app",
data: {
totalMoney: 0,
productList: [],
checkAllFlag:false,
limitNum:2,

//以下数据是为了TAB切换准备
tab:[{
"name":"1111"
},
{
"name":"2222"
},{
"name":"3333"
}],
testIndex:0 ,
activeContentIndex:0,
tabContent:[{
"value":"vvvvvvv1111111111"
},
{
"value":"vvvvvvv22222222"
},{
"value":"vvvvvvv3333333"
}],
stat:0
},
//可以内部注册也可以全局vue.filters注册
filters: {
formatMoney:function(value){
return "¥"+value.toFixed(2)
}
},
//代替1.0的ready方法,还是要配合nextTick使用
created: function() {
this.$nextTick(function () {
vm.cartView()
})
},
computed:{
totalMoney:function(){
var _this = this;
var totalMoney = 0;

this.productList.forEach(function(v,i){
if(v.checked){
totalMoney += v.productPrice * v.productQuentity;
}
})
return totalMoney
},
//VUE2.0 建议的给v-for增加条件限制的方法,现在只返回前两条数据
//注意slice和splice的区别 splice() 方法 用于插入、删除或替换数组的元素。会改变原数组
//对于数组对象来说,slice 方法提取 从 start下标起 以end下标 为结尾的
//一段元素(但不包括end下标的元素),然后返回新的数组,对原数组没有任何是影响,
productListFilter: function () {
return this.productList.slice(0,this.limitNum)
}
},


methods: {
cartView: function() {
//this指向VUE对象, 函数内的this变化了指向所以要先存起来
var _this = this
this.$http.get('data/data.json', {}).then(function(res) {
_this.productList = res.body.result.list;
// _this.totalMoney = res.body.result.totalMoney;

})

},
add:function(item){
item.productQuentity ++;
// this.calcTotalPrice()
},
reduce:function(item){
if(item.productQuentity === 0){
return
}
else
{
item.productQuentity --
}
// this.calcTotalPrice()
},
selectedProduct:function(item){
//判断item.checked是不是存在
if(typeof item.checked === 'undefined')
{
//全局注册一个checked属性
Vue.set(item,"checked",true)

//局部注册
//this.$set(item,"checked",true)
}
else
{
item.checked = !item.checked
//如果取消了其中一个的选择 那么也取消全选按钮
if(item.checked == false)
{
this.checkAllFlag = false
}
}

//this.calcTotalPrice()


},
checkAll:function(){
this.checkAllFlag = ! this.checkAllFlag;
var _this = this;
if(this.checkAllFlag){
this.productList.forEach(function(v,i){
Vue.set(v,"checked",true)
})
}
else{
this.productList.forEach(function(v,i){
Vue.set(v,"checked",false)
})
}

},

//前面用了computed属性 也可以单独使用一个方法
/* calcTotalPrice:function(){
var _this = this;
//每次先清0;
_this.totalMoney = 0;
this.productList.forEach(function(v,i){
if(v.checked){
_this.totalMoney += v.productPrice * v.productQuentity;
}
})
}*/
delProduct:function(index){
this.productList.splice(index,1)
},

tabChange:function(index){
this.testIndex=index;
//两种方法
this.activeContentIndex = index;
this.stat = index;
}
}

})
//全局过滤器
Vue.filter('money',function(value,type){
return "¥"+value.toFixed(2) + type
})
</script>
</body>

</html>


HTML

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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
<!DOCTYPE html>

<head>
<title>css3滑动搜索</title>
<meta charset="UTF-8">
<style>
html,
body {
height: 100%;
overflow: hidden;
}

.main {
width: 900px;
margin: 0 auto;
font-size: 0;
}

.main .tab {
display: inline-block;
width: 33%;
height: 40px;
line-height: 40px;
text-align: center;
border: 1px solid #ccc;
font-size: 14px;
border-right: 0px
}

.main .tab:last-child {
border-right: 1px solid #ccc;
position: relative;
}

.tab i {
width: 100%;
height: 2px;
background-color: red;
display: none;
transition: all .5s
}

.active {
color: red;
}

.active i {
display: block;
}

.tab a {
display: inline-block;
transition: all 0.8s ease-in-out;
}

.tab a:hover {
color: green;
transform: rotateY(360deg);
}

#dialg {
width: 400px;
height: 400px;
z-index: 10000;
background-color: #fff;
position: absolute;
display: none;
}

#dialg .close {
position: absolute;
right: 0;
top: 0
}
/*loading动画*/

.loadDiv {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
-webkit-transform: translate(-50%, -50%);
background-color: #fff;
z-index: 10000;
color: #fff;
line-height: 40px;
padding: 0 10px 0 10px;
border-radius: 3px;
white-space: nowrap;
background-color: rgba(0, 0, 0, 0.5);
text-align: center;
min-width: 80px;
}


.ldGif {
position: absolute;
left: 10px;
top: 5px;
}

@-webkit-keyframes line-scale {
0% {
-webkit-transform: scaley(1);
transform: scaley(1);
}
50% {
-webkit-transform: scaley(0.4);
transform: scaley(0.4);
}
100% {
-webkit-transform: scaley(1);
transform: scaley(1);
}
}

@keyframes line-scale {
0% {
-webkit-transform: scaley(1);
transform: scaley(1);
}
50% {
-webkit-transform: scaley(0.4);
transform: scaley(0.4);
}
100% {
-webkit-transform: scaley(1);
transform: scaley(1);
}
}

.line-scale > div:nth-child(1) {
-webkit-animation: line-scale 1s 0.1s infinite cubic-bezier(0.32, 0.96, 0.18, 1.08);
animation: line-scale 1s 0.1s infinite cubic-bezier(0.32, 0.96, 0.18, 1.08);
}

.line-scale > div:nth-child(2) {
-webkit-animation: line-scale 1s 0.2s infinite cubic-bezier(0.32, 0.96, 0.18, 1.08);
animation: line-scale 1s 0.2s infinite cubic-bezier(0.32, 0.96, 0.18, 1.08);
}

.line-scale > div:nth-child(3) {
-webkit-animation: line-scale 1s 0.3s infinite cubic-bezier(0.32, 0.96, 0.18, 1.08);
animation: line-scale 1s 0.3s infinite cubic-bezier(0.32, 0.96, 0.18, 1.08);
}

.line-scale > div:nth-child(4) {
-webkit-animation: line-scale 1s 0.4s infinite cubic-bezier(0.32, 0.96, 0.18, 1.08);
animation: line-scale 1s 0.4s infinite cubic-bezier(0.32, 0.96, 0.18, 1.08);
}

.line-scale > div:nth-child(5) {
-webkit-animation: line-scale 1s 0.5s infinite cubic-bezier(0.32, 0.96, 0.18, 1.08);
animation: line-scale 1s 0.5s infinite cubic-bezier(0.32, 0.96, 0.18, 1.08);
}

.line-scale > div {
background-color: #fff;
width: 4px;
height: 25px;
border-radius: 2px;
margin: 2px;
display: inline-block;
}
</style>
</head>

<body>
<div class="main">
<div class="tab active"><a>标题1</a><i></i></div>
<div class="tab"><a>标题1</a><i></i></div>
<div class="tab"><a>标题1</a><i></i></div>
</div>
<div class="content">1111
<button id="tcBtn">弹出层</button>
</div>
<div class="content" style="display: none;">
<button id="loadingBtn">loading</button>
<button id="hideLoadingBtn">hide</button>
<div id="loading-wrapper" style="width: 500px; height: 500px; border:1px solid #ccc;">
22222222222222222222222222
</div>
</div>
<div class="content" style="display: none;">3333</div>
<div id="dialg">
<p>弹出层自己写</p>
<div class="close">关闭</div>
</div>
<script src="jquery-1.10.1.min.js"></script>
<script type="text/javascript">
var Util = (function() {
var tab = function(el, className, content) {
var index = $(el).index();
$(el).addClass(className).siblings().removeClass(className);
$(content).eq(index).show().siblings(content).hide()
}
/* var tc = function(containerId) {
mengceng('body');
$(containerId).show();
$(containerId).css({
"position": "absolute",
"left": "0",
"top": "0",
"bottom": "0",
"right": "0",
"margin": "auto"
})
}*/

var tc= {
init:function(containerId){
mengceng('body');
$(containerId).show();
$(containerId).css({
"position": "absolute",
"left": "0",
"top": "0",
"bottom": "0",
"right": "0",
"margin": "auto"
})
},
closeTc:function(containerId){
$("#mengceng").remove();
$(containerId).hide()
}
}





var mengceng = function(dom) {
if (document.getElementById('mengceng') === null) {
var maskHtml = '<div id="mengceng"></div>';
if(dom){
$(dom).append(maskHtml)
}
else{
$("body").append(maskHtml);
}

$("#mengceng").css({
"background-color": "#000",
"width": "100%",
"height": "100%",
"position": "absolute",
"z-index": "9999",
"left": "0",
"top": "0",
"opacity": "0.6"
});
} else {
$("#mengceng").show()
}
}


/* var closeTc = function(containerId) {
$("#mengceng").remove();
$(containerId).hide()
}*/

var Loading = function(el, config) {
var defaults = {
msg: '数据加载中,请稍后',
mask: true,
img: true,
el: $(el),
callback: function() {
alert(1)
}
};
this.config = $.extend(defaults, config);
}

Loading.prototype = {
init: function() {
console.log(this.config)
var loadDiv = $("<div class='loadDiv'>" + this.config.msg + "</div>");
this.config.el.css("position", "relative");
this.config.el.append(loadDiv);
if (this.config.mask) {
mengceng(this.config.el);
}

if (this.config.img) {
var img = $("<div class='loader-inner line-scale'>" +
"<div></div>" +
"<div></div>" +
"<div></div>" +
"<div></div>" +
"<div></div>" +
"</div>");
this.config.el.find('.loadDiv').append(img);
} else {
var img = $("<div class='loadingGif'><img src='loading2.gif' width='80' /></div>");
this.config.el.find('.loadDiv').append(img);
}

},
destroy:function(){
$("#mengceng").remove();
$(".loadDiv").remove()
}
}



return {
tab: tab,
tc: tc,
loading: Loading
}
})();

$(function() {
$(".tab").on('click', function() {
Util.tab(this, "active", ".content")
})

$("#tcBtn").on("click", function() {
Util.tc.init("#dialg")
})

$(".close").on("click", function() {
Util.tc.closeTc("#dialg")
})


var load = new Util.loading("#loading-wrapper",{
msg:'123'
});
$("#loadingBtn").on("click", function() {
load.init()
})

$("#hideLoadingBtn").on("click",function(){
load.destroy()
})
})
</script>
</body>

</html>


}

====================================

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
71
72
73
74
75
<!DOCTYPE html>
<html>

<head>
<title>css style</title>
<link rel="stylesheet" type="text/css" href="test.css">
</head>
<style type="text/css">
#a{width: 300px; height: 50px; background-color: red;}
</style>
<body>
<div id="a">

</div>
</body>
<script type="text/javascript">
//公共方法
var Util = (function() {
function fn1(a) {
return alert(a)
}
var prefix = 'ficiton_reader_';
var StorageGetter = function(key) {
return localStorage.getItem(prefix + key);
}
var StorageSetter = function(key, val) {
return localStorage.setItem(prefix + key, val);
}
return {
fn1: fn1,
StorageGetter:StorageGetter,
StorageSetter:StorageSetter
}
})();

//具体功能实现
function method_1()
{
//var a = 1;
var init = function(){
Util.fn1("hahaha")
}
var fn2 = function(){
alert("method里的方法")
}
return {
init:init,
fn2:fn2
}
}

main();
//入口文件
function main(){
Util.fn1("first")
var obj= new method_1();
obj.init()
obj.fn2()

EventHandler()
}

//处理页面DOM的方法 可以先将DOM存起来 不用每次都去取
function EventHandler(){
var dom = {
a:document.getElementById("a")
}
dom.a.onclick=function(){
alert(1)
}
}
</script>

</html>

安装步骤

1.安装NODEJS环境

2,全局安装 gulp npm install -g gulp

3,拷贝gulpfile.js, package.json文件,目录结构参考
https://github.com/weibsgz/easy-gulp

4,目录下运行npm install

5, 目录下运行gulp

列子:https://github.com/weibsgz/easy-gulp

gulpfile.js的配置

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
//导入工具包 require('node_modules里对应模块')
var gulp = require('gulp'); //本地安装gulp所用到的地方
var fileinclude = require('gulp-file-include'); //包含HTML
var connect = require('gulp-connect'); //本地服务
var imagemin = require('gulp-imagemin'); //图片压缩
var watch = require('gulp-watch'); //监听
var less = require('gulp-less');
var notify = require('gulp-notify'); //处理LESS错误
var plumber = require('gulp-plumber'); //处理LESS错误
var browserSync = require('browser-sync');
var reload = browserSync.reload;


//include html并刷新服务
gulp.task('fileinclude', function(done) {
gulp.src(['src/html/*.html'])
.pipe(fileinclude({
prefix: '@@',
basepath: '@file'
}))
.pipe(gulp.dest('src/page'))
.on('end', done)
.pipe(reload({ stream: true }))
});


gulp.task('testLess', function () {
gulp.src('src/css/*.less')
.pipe(plumber({errorHandler: notify.onError('Error: <%= error.message %>')}))
.pipe(less())
.pipe(gulp.dest('src/css'))
});


// 监视文件改动并重新载入
gulp.task('serve', function() {
browserSync({
port: 9000,
server: {
baseDir: 'src/'
}
});
});

//监听所有HTML JS CSS改动
gulp.task('watch', function () {
// gulp.watch(['src/css/*','src/css/*.less','src/html/*.html','src/js/*','src/images/*'], ['testLess','jstodist','csstodist','fileinclude','imagemin']);
gulp.watch(['src/css/*.less'], ['testLess']);
gulp.watch(['src/html/**/*.html'], ['fileinclude']);
gulp.watch("src/**/*.*").on('change', browserSync.reload);

});

gulp.task('default',['testLess','fileinclude','serve','watch']);

package.json的配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
{
"name": "njga",
"version": "1.0.0",
"description": "test",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"gulp": "^3.9.1",
"browser-sync": "^2.17.3",
"gulp-connect": "^5.0.0",
"gulp-file-include": "^1.0.0",
"gulp-imagemin": "^3.0.3",
"gulp-less": "^3.1.0",
"gulp-notify": "^2.2.0",
"gulp-plumber": "^1.1.0",
"gulp-watch": "^4.3.10"
}
}

  • content
    {:toc}

自己写的扩展JQ的LOADING插件,九次方作业

HTML

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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<!DOCTYPE html>

<head>
<title>数据加载插件</title>
<link rel="stylesheet" type="text/css" href="../css/loading.css">
<script type="text/javascript" src="../js/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="../js/loading.js"></script>
<style type="text/css">
* {
margin: 0;
padding: 0
}

.main {
width: 100%;
overflow: hidden;
}

.left {
float: left;
width: 50%;
border-right: 1px solid #ccc;
height: 500px;
}

.right {
float: right;
width: 49%;
height: 500px;
}

.loadBtn,.doneBtn {
display: inline-block;
height: 40px;
line-height: 40px;
text-align: center;
color: #fff;
background: blue;
border: none;
padding:0 10px;
}

.doneBtn{background-color: red}
</style>
</head>

<body>
<button id="changeBtn" class="doneBtn">读取完毕</button>
<button id="changeBtn1" class="loadBtn">开始读取</button>
<div class="main">
<div id="msg" class="left">
<p>内容内容</p>
<p>内容内容</p>
<p>内容内容</p>
</div>
<div id="msg1" class="right">
</div>
</div>
<script type="text/javascript">
$(document).ready(function() {
var msg = $("#msg").myLoading({
msg: '请稍后...',
mask: true,
img:true
});
msg.init()

var msg1 = $("#msg1").myLoading({mask:false});
msg1.init()

$("#changeBtn").on("click", function() {
msg.destroy();
})

$("#changeBtn1").on("click", function() {
msg.init()
})

});


</script>
</body>

</html>

loading.css

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
71
72
73
74
75
76
77
78
79
80
81
.loadDiv {
position:absolute;
top:50%;
left:50%;
transform:translate(-50%,-50%);
-webkit-transform:translate(-50%,-50%);
background-color: #fff;
z-index: 9;
color:#fff;
line-height: 40px;
padding:0 10px 0 10px;
border-radius: 3px;
white-space:nowrap;
background-color:rgba(0,0,0,0.5);
text-align:center;

}

.mask{
background: #333;
filter: alpha(opacity=30);
opacity: 0.3;
position: absolute;
left: 0px;
top: 0px;
width: 100%;
height: 100%;
overflow: hidden;
z-index: 1;
}
.ldGif{
position: absolute;
left: 10px;
top: 5px;
}


.spinner {
width: 150px;
text-align: center;
}

.spinner > div {
width: 15px;
height: 15px;
background-color: #67CF22;

border-radius: 100%;
display: inline-block;
-webkit-animation: bouncedelay 1.4s infinite ease-in-out;
animation: bouncedelay 1.4s infinite ease-in-out;
/* Prevent first frame from flickering when animation starts */
-webkit-animation-fill-mode: both;
animation-fill-mode: both;
}

.spinner .bounce1 {
-webkit-animation-delay: -0.32s;
animation-delay: -0.32s;
}

.spinner .bounce2 {
-webkit-animation-delay: -0.16s;
animation-delay: -0.16s;
}

@-webkit-keyframes bouncedelay {
0%,100% { -webkit-transform: scale(0.0) }
40% { -webkit-transform: scale(1.0) }
}

@keyframes bouncedelay {
0%, 100% {
transform: scale(0.0);
-webkit-transform: scale(0.0);
} 40% {
transform: scale(1.0);
-webkit-transform: scale(1.0);
}
}

loading.js

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
(function($) {
$.fn.extend({
myLoading: function(config) {
var defaults = {
msg: '数据加载中',
mask:true,
img:true
};

var config = $.extend(defaults, config);

this.init = function() {
this.destroy();
var loadDiv = $("<div class='loadDiv'>" + config.msg + "</div>");
this.css("position", "relative");
this.append(loadDiv);

if(config.mask){
var mask = $("<div class='mask'></div>");
this.append(mask);
}

if(config.img){
var img = $("<div class='spinner'>"+
"<div class='bounce1'></div>"+
"<div class='bounce2'></div>"+
"<div class='bounce3'></div>"+
"</div>");
this.find('.loadDiv').append(img);
}

}


this.destroy = function() {
$(this).find('.loadDiv').hide();
$(this).find(".mask").hide()
}
return this;
}
});
})(window.jQuery);


code

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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<!DOCTYPE html>
<head>
<title>css3滑动</title>
<link rel="stylesheet" type="text/css" href="../css/reset.css">
<script type="text/javascript" src="../js/jquery-1.7.2.min.js"></script>
<style>
* {
margin: 0;
padding: 0
}

.main {
font-size: 24px;
width: 900px;
margin: 0 auto;
}

.main p {
margin-top: 10px;
}

.main input,
.main textarea {
border: 1px solid #ccc;
width: 300px;
padding: 5px;
}

.main input {
height: 30px;
line-height: 30px;
}

.main textarea {
width: 300px;
height: 100px;
}

.main button {
color: #fff;
background: blue;
width: 100px;
height: 30px;
line-height: 30px;
text-align: center;
border: none;
cursor: pointer;
}

.main button:hover {
opacity: .6
}
</style>
</head>

<body>
<div class="main">
<p>
<input id="colorInput" placeholder="请输入颜色值比如#ccc,red" />
</p>
<p>
<textarea id="textInput" placeholder="请输入文本内容"></textarea>
</p>
<p>
<input id="speedInput" placeholder="请输入打印速度:单位ms" />
</p>
<p>
<button onclick="doThis()">确定</button>
</p>
<div id="word-wrapper-js" class="word-wrapper-js"></div>
</div>
<script type="text/javascript">
var textPrint = {
init: function(config) {
this.id = $(config.id);
this.text = config.text || '你什么都没输入';
this.color = config.color || '#666';
this.speed = config.speed || 100;
//this.render();
//可链式调用
return this;
},
//渲染元素
render: function() {
var typeWord = '',
i = 0,
speed = this.speed,
_this = this,
cur = "_"
var typing = setInterval(function() {
if (_this.text[i] == "\n") {
typeWord = typeWord + "<br />"
}

typeWord += _this.text[i];

_this.id.css('color', _this.color).html(typeWord + cur);
i++;
if (i == _this.text.length) {

clearInterval(typing);

}
}, _this.speed)
}
}



function doThis() {
var color = $("#colorInput").val();
var text = $("#textInput").val();
var speed = $("#speedInput").val();

textPrint.init({
id: '#word-wrapper-js',
text: text,
color: color,
speed: speed
}).render();


}
</script>
</body>

</html>

vue 1.0

http://vuejs.org.cn/guide/

vue 1.0 router

https://github.com/vuejs/vue-router/tree/1.0/docs/zh-cn

flex

https://www.w3cplus.com/css3/understanding-flexbox-everything-you-need-to-know.html?from=groupmessage&isappinstalled=0

Gulp中的增量编译

http://fedvic.com/2016/01/29/gulpIncrementalBuild/

SVG

http://mp.weixin.qq.com/s?__biz=MzAxODE2MjM1MA==&mid=2651553180&idx=2&sn=612991e9ea514a1e500a2002c50b183e&chksm=8025aa5db752234b2c1d8e55954f4cb63067a3a137cdec7d1917b13239b2de1f7e58153e3569&mpshare=1&scene=1&srcid=12024zyw8IOv0qMjBaE8jIY0#rd

https://brucewar.gitbooks.io/svg-tutorial/1.SVG%E6%95%99%E7%A8%8B.html

react 中文

https://doc.react-china.org/

html

1
2
3
4
5
<div v-show="detailShow" class="detail" transition="fade">
.
.
.
</div>

css

1
2
3
4
5
6
7
8
9
10
11
12
13
.detail{position: fixed;z-index: 100;width: 100%; height: 100%;overflow:auto;background: rgba(7,17,27,0.8);top: 0; left: 0;transition: all 0.5s;backdrop-filter:blur(10px);
}
/*动画结束的状态*/
.detail.fade-transition{
opacity: 1;
background: rgba(7,17,27,0.8);
}
/*动画开始的状态*/
.detail.fade-enter,.detail.fade-leave{
opacity: 0;
background: rgba(7,17,27,0);
}

star组件的实现(星星评分)

header.vue(父组件)

1
<star :size="48" :score="seller.score"></star>

:size=”48” 是传的星星大小,实际项目中可以不用,seller.score是后台传过来的分数比如4.2,3.6之类的

1
2
3
4
5
6
7
8
9
10
11
12
13
    import star from 'components/star/star'
export default{
props:{
//props接受父组件传递来的props,父组件中定义了<v-head :seller>
seller:{
type:Object
}
},

components: {
star
}
}

app.vue(子组件)

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
71
72
    <template>
<div class="star" :class="starType">
<!-- 循环星星,星星的每个CLASS不同,itemClass是单独的样式:on half off, star-item是一样的样式 track-by="$index不加会有警告 -->
<span v-for="itemClass in itemClasses" :class="itemClass" class="star-item" track-by="$index"></span>
</div>
</template>
<script>
const LENGTH = 5;
const CLS_ON = 'on';
const CLS_HALF = 'half';
const CLS_OFF = 'off';
export default{
props:{
size:{
type:Number
},
score:{
type:Number
}
},
computed:{
starType(){
return 'star-'+this.size
},
itemClasses(){
var result = [];
//四舍五入 小数位数大于0.5的 取完后会有小数保留,反之只保留整数
let score = Math.floor(this.score*2)/2;

//是否有小数,如果scrore是小数 % 1后就不是0
var hasDecimal = score % 1 !== 0 ;
console.log(hasDecimal)
//整数有多少分,也就是有几个全星星
let integer = Math.floor(score);
console.info(integer)

//先把整的星星放进去
for(let i=0; i<integer; i++)
{

result.push(CLS_ON);
}
console.log(result)

//如果有小数,就放进去一个半星,半星最多有一个
if(hasDecimal){
result.push(CLS_HALF)
}

//如果不足5颗星,补足黑色星星
while(result.length<LENGTH)
{
result.push(CLS_OFF);
}

return result;
}
}
}
</script>
<style>
.star{font-size: 0}
.star .star-item{display: inline-block; background-repeat: no-repeat;}
.star .star-item:last-child{margin-right: 0}
.star-48 .star-item{ width: 20px; height: 20px; margin-right: 22px; background-size: 20px 20px;}
.star-48 .star-item.on{background-image:url("star48_on@3x.png");}
.star-48 .star-item.half{background-image:url("star48_half@3x.png");}
.star-48 .star-item.off{background-image:url("star48_off@3x.png");}
.star-36 .star-item{}
.star-24 .star-item{}
</style>