forked from component/scroll-to
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample-container.html
More file actions
66 lines (57 loc) · 1.25 KB
/
example-container.html
File metadata and controls
66 lines (57 loc) · 1.25 KB
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
<html>
<head>
<title>scroll-to - smooth javascript window scrolling with requestAnimationFrame</title>
<style>
body {
padding: 50px;
overflow: hidden;
}
div {
position: relative;
overflow: auto;
width: 500px;
height: 300px;
}
ul {
min-width: 1500px;
overflow: hidden;
}
ul li {
margin: 10px;
padding: 5px;
list-style: none;
display: block;
float: left;
width: 100px;
height: 100px;
border: 1px solid #eee;
text-align: center;
line-height: 100px;
}
</style>
</head>
<body>
<div><ul></ul></div>
<script src="build/build.js"></script>
<script>
var scroll = require('scroll-to');
var events = require('event');
var ul = document.querySelector('ul');
for (var i = 0; i < 500; i++) {
var li = document.createElement('li');
li.textContent = 'item ' + i;
ul.appendChild(li);
}
var options = {
container: document.querySelector('div')
}
ul.addEventListener('click', function (e) {
var li = e.target
var x = li.offsetLeft
var y = li.offsetTop
console.log('scrolling to (%s, %s)', x, y);
scroll(x, y, options);
})
</script>
</body>
</html>