-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest2.html
73 lines (66 loc) · 1.96 KB
/
test2.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script src="https://cdn.bootcss.com/rxjs/5.4.0/Rx.min.js"></script>
<style>
#card {
width: 100px;
height: 100px;
background: #90f;
}
#title {
width: 100px;
height: 100px;
background: #eee;
}
</style>
</head>
<body>
<div id="card"></div>
<div id="title"></div>
<script>
const docElm = document.documentElement;
const cardElm = document.querySelector('#card');
const titleElm = document.querySelector('#title');
function lerp(start, end) {
const dx = end.x - start.x;
const dy = end.y - start.y;
return {
x: start.x + dx * 0.1,
y: start.y + dy * 0.1,
};
}
const {
clientWidth,
clientHeight
} = docElm;
const num$ = Rx.Observable.from([1,2,3,4,5])
num$.subscribe(function(data){
console.log(data)
})
const mouseMove$ = Rx.Observable
.fromEvent(docElm, 'mousemove')
.map(event => ({
x: event.clientX,
y: event.clientY
}))
const touchMove$ = Rx.Observable
.fromEvent(docElm, 'touchmove').map(event => ({
x: event.touches[0].clientX,
y: event.touches[0].clientY
}));
const move$ = Rx.Observable.merge(mouseMove$, touchMove$);
move$.subscribe(pos => {
const rotX = (pos.y / clientHeight * -50) - 25;
const rotY = (pos.x / clientWidth * 50) - 25;
cardElm.style = `
transform: rotateX(${rotX}deg) rotateY(${rotY}deg);
`;
});
</script>
</body>
</html>