Skip to content

Commit 22307ea

Browse files
committed
fix onload bug
1 parent 28f94d7 commit 22307ea

6 files changed

Lines changed: 36 additions & 9 deletions

File tree

‎components/firstscreen/example/example.html‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<meta name="author" content="summer">
66
<link rel="stylesheet" href="../../reset/reset.css">
77
<link rel="stylesheet" href="../firstscreen.css">
8+
<script src="../../onload/onload.js"></script>
89
<script src="../../EventUtil/EventUtil.js"></script>
910
<script src="../firstscreen.js"></script>
1011
<title>HashCoding--百度IFE</title>

‎components/firstscreen/firstscreen.js‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
(function(et) {
2-
window.onload = function() {
2+
addLoadListener(_firstscreen);
3+
4+
function _firstscreen() {
35
var arow = document.getElementById("arow_down"),
46
h = document.documentElement.clientHeight;
57

‎components/onload/onload.js‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
var addLoadListener = function(fn){
2+
if (typeof window.addEventListener != 'undefined'){
3+
window.addEventListener('load',fn,false);
4+
}else if(typeof document.addEventListener != 'undefined'){
5+
document.addEventListener('load',fn,false);
6+
}else if (typeof window.attachEvent != 'undefined'){
7+
window.attachEvent('onload',fn);
8+
}else{
9+
var oldfn = window.onload;
10+
if(typeof window.onload != 'function'){
11+
window.onload = fn;
12+
}else{
13+
window.onload = function(){
14+
oldfn();
15+
fn();
16+
};
17+
}
18+
}
19+
};

‎components/scroll/example/example.html‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<meta charset="UTF-8">
55
<title>Title</title>
66
<link rel="stylesheet" href="../scroll.css">
7+
<script src="../../onload/onload.js"></script>
78
<script src="../../EventUtil/EventUtil.js"></script>
89
<script src="../scroll.js"></script>
910
</head>

‎components/scroll/scroll.js‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
/**
22
* Created by rccoder on 2016/3/10.
33
*/
4-
window.onload = function() {
5-
(function(et) {
4+
(function(et) {
5+
addLoadListener(_scroll);
66

7+
function _scroll() {
78
var scroll = document.getElementById("scroll"),
89
win = window;
910

@@ -25,6 +26,6 @@ window.onload = function() {
2526
}
2627
}, 10)
2728
});
29+
};
2830

29-
})(EventUtil);
30-
}
31+
})(EventUtil);

‎index.html‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77
<link rel="stylesheet" href="./components/firstscreen/firstscreen.css">
88
<link rel="stylesheet" href="./components/scroll/scroll.css">
99

10-
<script src="./components/EventUtil/EventUtil.js"></script>
11-
<script src="./components/firstscreen/firstscreen.js"></script>
12-
<script src="./components/scroll/scroll.js"></script>
10+
1311
<title>HashCoding--百度IFE</title>
1412
</head>
1513
<body>
@@ -104,10 +102,15 @@
104102
<i class="down">&#xe682;</i>
105103
</div>
106104
</section>
107-
108105
<section class="section scroll" id="scroll">
109106
<img src="./components/scroll/scroll.png" alt="">
110107
</section>
111108
</div>
109+
110+
<script src="./components/onload/onload.js"></script>
111+
<script src="./components/EventUtil/EventUtil.js"></script>
112+
<script src="./components/firstscreen/firstscreen.js"></script>
113+
<script src="./components/scroll/scroll.js"></script>
114+
112115
</body>
113116
</html>

0 commit comments

Comments
 (0)