-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo2.html
83 lines (79 loc) · 2.28 KB
/
demo2.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
* {
margin: 0;
padding: 0;
}
#container {
margin-top: 400px;
text-align: center
}
.box {
display: inline-block;
position: relative;
width: 200px;
height: 200px;
border: 5px solid #333;
font-size: 0;
}
.item-wrap {
position: absolute;
top: 0;
left: 0;
height: auto;
width: inherit;
}
.item {
height: 300px;
width: inherit;
background: #fc4;
font-size: 30px;
text-align: center;
box-sizing: border-box;
}
.item-copy {
/*background: #cf4;*/
}
</style>
</head>
<body>
<div id="container" style="--height: -100%">
<div class="box">
<div class="item-wrap marquee-content">
<div class="item">block 1<br/>block 2<br/>block 1<br/>block 2<br/>block 1<br/>block 2<br/></div>
<div class="item item-copy" style="border-top: 1px solid #c4f; ">block 1<br/>block 2<br/>block 1<br/>block 2<br/>block 1<br/>block 2<br/></div>
</div>
</div>
<div class="box" style="overflow: hidden">
<div class="item-wrap marquee-content">
<div class="item">block 1<br/>block 2<br/>block 1<br/>block 2<br/>block 1<br/>block 2<br/></div>
<div class="item item-copy">block 1<br/>block 2<br/>block 1<br/>block 2<br/>block 1<br/>block 2<br/></div>
</div>
</div>
</div>
<script>
let box = document.querySelector('.box');
let item = document.querySelector('.item');
let boxHeight = box.clientHeight;
let contentHeight = item.clientHeight;
let cssvar = contentHeight + contentHeight - boxHeight;
document.getElementById('container').setAttribute('style', `--height: -${cssvar}px`)
</script>
</body>
<style>
@keyframes marqueeAnim {
0% { transform: translateY(0); }
100% { transform: translateY(var(--height)); }
}
.marquee-content{
animation: marqueeAnim 5s linear 0s infinite;
}
.marquee-content:hover {
animation-play-state: paused;
}
</style>
</html>