vue监听滚动事件实现滚动监听
1234567891011121314151617181920212223242526272829303132333435
·
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
|
<!DOCTYPE html>
<
html
lang
=
"en"
>
<
head
>
<
meta
charset
=
"UTF-8"
>
<
title
>Document</
title
>
<
style
type
=
"text/css"
>
#box {
width: 100%;
height: 2000px;
}
</
style
>
</
head
>
<
div
id
=
"box"
></
div
>
<
body
>
<!-- vue监听滚动事件 -->
<
script
type
=
"text/javascript"
>
var vm = new Vue({
el:'#box',
data() {
return {
scroll: ''
}
},
methods: {
menu() {
this.scroll = document.body.scrollTop;
console.log(this.scroll)
}
},
mounted() {
window.addEventListener('scroll', this.menu)
},
})
</
script
>
</
body
>
</
html
>
|
更多推荐
已为社区贡献16条内容
所有评论(0)