Skip to content

Commit 3166527

Browse files
committed
muke demo.html
1 parent cd62632 commit 3166527

20 files changed

+170
-158
lines changed

demo/回调函数.html

-98
This file was deleted.

version/src/demo.html

+28-60
Original file line numberDiff line numberDiff line change
@@ -10,68 +10,36 @@
1010
</head>
1111
<body>
1212

13+
<div>123</div>
14+
1315
<script type="text/javascript">
16+
17+
var ele = document.createElement('div')
18+
19+
ele.className = "message"
20+
21+
var testNode = document.createTextNode('hello world');
22+
23+
ele.appendChild(testNode);
24+
25+
var testNode1 = document.createTextNode('aaron');
26+
27+
ele.appendChild(testNode1);
28+
29+
document.body.appendChild(ele)
30+
31+
32+
ele.normalize();
33+
34+
console.log(ele)
35+
36+
37+
38+
// var div = document.querySelectorAll('div')[0];
39+
40+
// div.firstChild.nodeValue = 'chenwen <li> daaa </li> sdf';
1441

15-
function fn1() {
16-
var defer = $.Deferred();
17-
setTimeout(function(){
18-
defer.resolve('fn1');
19-
},500)
20-
return defer;
21-
}
22-
23-
function fn2(){
24-
var defer = $.Deferred();
25-
setTimeout(function(){
26-
defer.resolve('fn2');
27-
},1000)
28-
return defer;
29-
}
30-
31-
// $.when(fn1(), fn2()).then(function() {
32-
// console.log('成功',arguments)
33-
// },function(){
34-
// console.log('失败',arguments)
35-
// })
36-
37-
38-
function when() {
39-
40-
var resolveContexts, resolveValues,
41-
resolveValues = [].slice.call(arguments),
42-
remaining = resolveValues.length;
43-
44-
//内部deferred对象
45-
var deferred = $.Deferred();
46-
47-
function collector(i, contexts, values) {
48-
return function(value) {
49-
contexts[i] = this;
50-
values[i] = arguments.length > 1 ? [].slice.call(arguments)(arguments) : value;
51-
if (remaining === 1) {
52-
deferred.resolveWith(contexts, values);
53-
} else {
54-
--remaining;
55-
}
56-
};
57-
};
58-
59-
var resolveContexts,resolveValues;
60-
for (var i = 0; i < remaining; i++) {
61-
progressValues = new Array( resolveValues.length );
62-
resolveContexts = new Array( resolveValues.length );
63-
resolveValues[i].promise()
64-
.done(collector(i, resolveContexts, resolveValues))
65-
.fail(deferred.reject)
66-
}
67-
68-
return deferred;
69-
}
70-
71-
72-
when(fn1(), fn2()).done(function() {
73-
console.log(arguments)
74-
})
42+
// console.log(div)
7543

7644
</script>
7745

version/src/回调函数.html

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<!DOCTYPE HTML>
2+
<html>
3+
<head>
4+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
5+
<script src="http://img.mukewang.com/down/540812440001e40e00000000.js" type="text/javascript"></script>
6+
<script src="http://img.mukewang.com/down/541f6ff70001a0a500000000.js" type="text/javascript"></script>
7+
8+
<title></title>
9+
</head>
10+
<body>
11+
12+
<div id="target">
13+
点击触发事件回调
14+
</div>
15+
16+
17+
<img id="book" alt="" width="100" height="123"
18+
style="position: relative; left: 10px;background:#ccc" />
19+
20+
<div id="clickme">
21+
点击动画等待动画结束后回调
22+
</div>
23+
24+
<script type="text/javascript">
25+
26+
27+
//同步回调
28+
function callback(args, fn) {
29+
var args = args * 2;
30+
fn(args);
31+
}
32+
33+
callback(2, function(value) {
34+
alert(value)
35+
})
36+
37+
38+
//异步事件回调
39+
$("#target").click(function() {
40+
alert("触发回调函数");
41+
});
42+
43+
//异步动画回调
44+
$('#clickme').click(function() {
45+
$('#book').animate({
46+
opacity: 0.25,
47+
left: '+=50',
48+
height: 'toggle'
49+
}, 1000, function() {
50+
alert('动画结束回调')
51+
});
52+
});
53+
54+
</script>
55+
</body>
56+
</html>
57+
58+
59+
60+
61+
62+
63+
64+
65+
66+
67+
68+
69+
70+
71+
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<!DOCTYPE HTML>
2+
<html>
3+
<head>
4+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
5+
<script src="http://img.mukewang.com/down/540812440001e40e00000000.js" type="text/javascript"></script>
6+
<script src="http://img.mukewang.com/down/541f6ff70001a0a500000000.js" type="text/javascript"></script>
7+
8+
<title></title>
9+
</head>
10+
<body>
11+
12+
<div id="target">
13+
点击触发事件回调
14+
</div>
15+
16+
17+
<img id="book" alt="" width="100" height="123"
18+
style="position: relative; left: 10px;background:#ccc" />
19+
20+
<div id="clickme">
21+
点击动画等待动画结束后回调
22+
</div>
23+
24+
<script type="text/javascript">
25+
26+
27+
//同步回调
28+
function callback(args, fn) {
29+
var args = args * 2;
30+
fn(args);
31+
}
32+
33+
callback(2, function(value) {
34+
alert(value)
35+
})
36+
37+
38+
//异步事件回调
39+
$("#target").click(function() {
40+
alert("触发回调函数");
41+
});
42+
43+
//异步动画回调
44+
$('#clickme').click(function() {
45+
$('#book').animate({
46+
opacity: 0.25,
47+
left: '+=50',
48+
height: 'toggle'
49+
}, 1000, function() {
50+
alert('动画结束回调')
51+
});
52+
});
53+
54+
</script>
55+
</body>
56+
</html>
57+
58+
59+
60+
61+
62+
63+
64+
65+
66+
67+
68+
69+
70+
71+
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)