forked from alibaba/weex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsticky-demo.we
81 lines (79 loc) · 1.75 KB
/
sticky-demo.we
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
<style>
.top {
width: 750;
height: 200px;
}
.ct {
width: 750;
height: 1000;
}
.content {
width: 750;
height: 1000px;
background-color: green;
}
.header {
width: 750;
height: 80;
}
.header1 {
background-color: yellow;
}
.header2 {
background-color: red;
height: 200px;
}
.fixed1 {
color: #fff;
position: fixed;
width: 300px;
height: 100px;
background-color: #999;
border: 1px solid #666;
z-index: 999;
}
.fixed2 {
color: #fff;
position: fixed;
top: 300px;
width: 300px;
height: 100px;
background-color: #999;
border: 1px solid #666;
z-index: 999;
}
</style>
<template>
<div>
<div class="top"></div>
<scroller class="ct">
<div class="fixed1" style="position:{{fixPosition}};top:{{fixTop}};" onclick="toggleSticky"><text>TOGGLE STICKY</text></div>
<div class="fixed2" onclick="toggleFixed"><text>TOGGLE FIXED</text></div>
<div class="content"></div>
<div class="header header1" style="position:{{position}}"></div>
<div class="content"></div>
<div class="header header2" style="position:{{position}}"></div>
<div class="content"></div>
<div class="content"></div>
</scroller>
</div>
</template>
<script>
module.exports = {
data: {
position: 'sticky',
fixPosition: 'fixed',
fixTop: 100,
},
methods: {
toggleSticky: function () {
this.position = this.position === 'sticky' ? 'relative' : 'sticky'
},
toggleFixed: function () {
const nextPosition = this.fixPosition === 'fixed' ? 'relative' : 'fixed'
this.fixPosition = nextPosition
this.fixTop = nextPosition === 'fixed' ? 50 : 0
}
}
}
</script>