forked from euan-smith/ie11-scroll-into-view
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
157 lines (153 loc) · 5.48 KB
/
index.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
<!doctype html>
<html>
<head>
<title>Testbed for IE11 scrollIntoView fix</title>
<script src="node_modules/jquery/dist/jquery.js"></script>
<script src="ie11-scroll-into-view.js"></script>
<style>
div {
margin: 0;
padding: 0;
}
.wrapper {
width: 120%;
}
.overflow-x-scroll {
width: 100%;
overflow-x: scroll;
}
.sections {
display: flex;
}
.section {
width: 33%;
}
.overflow-scroll {
display: block;
width: 100%;
height: 200px;
overflow-y: scroll;
}
.buttons {
display: block;
width: 100%;
}
button {
display: block;
}
#message {
padding: 10px;
font-size: 20px;
height: 40px;
border: 1px solid #999999;
background-color: #f6f6f6;
}
#message p {
margin: 0;
}
.message-ok {
color: green;
}
.message-error {
color: red;
}
</style>
</head>
<body>
<h1>Testbed to reproduce IE 11 scrollIntoView() bug</h1>
<div id="message">
<p>Click the "Scroll to top/bottom" buttons to trigger scrollIntoView() calls.</p>
</div>
<div class="overflow-x-scroll" id="horizontal-scroller">
<div class="wrapper">
<div class="sections">
<div class="section">
<div class="overflow-scroll">
<ol>
<li id="first-foo">Foo</li>
<li>Foo</li><li>Foo</li><li>Foo</li><li>Foo</li><li>Foo</li><li>Foo</li><li>Foo</li><li>Foo</li><li>Foo</li>
<li>Foo</li><li>Foo</li><li>Foo</li><li>Foo</li><li>Foo</li><li>Foo</li><li>Foo</li><li>Foo</li><li>Foo</li>
<li>Foo</li><li>Foo</li><li>Foo</li><li>Foo</li><li>Foo</li><li>Foo</li><li>Foo</li><li>Foo</li><li>Foo</li>
<li id="last-foo">Foo</li>
</ol>
</div>
<div class="buttons">
<button data-section="foo" data-to="first">Scroll to top</button>
<button data-section="foo" data-to="last">Scroll to bottom</button>
</div>
</div>
<div class="section">
<div class="overflow-scroll">
<ol>
<li id="first-bar">Bar</li>
<li>Bar</li><li>Bar</li><li>Bar</li><li>Bar</li><li>Bar</li><li>Bar</li><li>Bar</li><li>Bar</li><li>Bar</li>
<li>Bar</li><li>Bar</li><li>Bar</li><li>Bar</li><li>Bar</li><li>Bar</li><li>Bar</li><li>Bar</li><li>Bar</li>
<li>Bar</li><li>Bar</li><li>Bar</li><li>Bar</li><li>Bar</li><li>Bar</li><li>Bar</li><li>Bar</li><li>Bar</li>
<li id="last-bar">Bar</li>
</ol>
</div>
<div class="buttons">
<button data-section="bar" data-to="first">Scroll to top</button>
<button data-section="bar" data-to="last">Scroll to bottom</button>
</div>
</div>
<div class="section">
<div class="overflow-scroll">
<ol>
<li id="first-fox">Fox</li>
<li>Fox</li><li>Fox</li><li>Fox</li><li>Fox</li><li>Fox</li><li>Fox</li><li>Fox</li><li>Fox</li><li>Fox</li>
<li>Fox</li><li>Fox</li><li>Fox</li><li>Fox</li><li>Fox</li><li>Fox</li><li>Fox</li><li>Fox</li><li>Fox</li>
<li>Fox</li><li>Fox</li><li>Fox</li><li>Fox</li><li>Fox</li><li>Fox</li><li>Fox</li><li>Fox</li><li>Fox</li>
<li id="last-fox">Fox</li>
</ol>
</div>
<div class="buttons">
<button data-section="fox" data-to="first">Scroll to top</button>
<button data-section="fox" data-to="last">Scroll to bottom</button>
</div>
</div>
</div>
</div>
</div>
<div class="sections">
<div class="section">
<div class="overflow-scroll">
<ol>
<li id="first-baz">Baz</li>
<li id="last-baz">Baz</li>
</ol>
</div>
<div class="buttons">
<button data-section="baz" data-to="first">Scroll to top</button>
<button data-section="baz" data-to="last">Scroll to bottom</button>
</div>
</div>
</div>
<script>
function getWrapperScrollLeft() {
return document.getElementById('horizontal-scroller').scrollLeft;
}
Array.prototype.slice.call(document.querySelectorAll('button')).forEach(function (button) {
button.addEventListener('click', function () {
var scrollLeftBefore = getWrapperScrollLeft();
var to = button.getAttribute('data-to') + '-' + button.getAttribute('data-section');
console.log('Jump to', to);
var timeout=setTimeout(function(){
document.getElementById('message').innerHTML =
'<p class="message-error">Test failed: scrollIntoView has taken more than 2 seconds.</p>';
},2000);
document.getElementById(to).scrollIntoView();
clearTimeout(timeout);
var scrollLeftAfter = getWrapperScrollLeft();
if (scrollLeftBefore === scrollLeftAfter) {
document.getElementById('message').innerHTML =
'<p class="message-ok">Test passed: Behavior of scrollIntoView was as expected.</p>';
} else {
document.getElementById('message').innerHTML =
'<p class="message-error">Test failed: the browser scrolled horizontally.</p>';
}
});
});
</script>
</body>
</html>