Skip to content

Commit 05053ab

Browse files
author
alistar
committed
增加一个scroll事件的监听
1 parent 6f37a2e commit 05053ab

File tree

4 files changed

+25
-4
lines changed

4 files changed

+25
-4
lines changed

src/DemoDescription.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#### navbar 注意事项
1+
#### test.vue(navbar) 注意事项
22
1 安装swiper3 npm i vue-awesome-swiper@2.6.7 -S
33
2 每一个slide的width,强制auto
4-
TODO 数据异步获取 切换动画效果 上拉加载
4+
TODO 数据异步获取 切换动画效果 上拉加载
5+
监控scroll事件

src/commitDetail.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@ npm i node-sass sass-loader http-proxy-middleware -D
1212
note: https://github.com/KokoTa/Vue2-transition 路由切换动画
1313
d5c6d2bf873068e96234181d1afc507fce71a19a
1414
*** 引入store 改写了请求方式 完成首页和登录页
15+
6f37a2e017ae903142b25db9a9e67b06e5138412
16+
*** 增加一个scroll事件的监听

src/components/common/test.vue

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<div>
2+
<div style="height:2000px">
33
<swiper :options="swiperOption" :not-next-tick="swiperOption.notNextTick" ref="swiper1">
44
<!-- slides -->
55
<swiper-slide
@@ -14,6 +14,7 @@
1414
<!-- slides -->
1515
<swiper-slide>I'm Slide {{floorNavData.activeIndex}}</swiper-slide>
1616
</swiper>
17+
<div class="lorem" :style="{opacity: opacityValue}">Lorem ipsum tam similique dolor veniam iure eveniet non vel ut eum iusto sapiente est.</div>
1718
</div>
1819
</template>
1920
<script>
@@ -44,7 +45,8 @@ export default {
4445
// setCurrentSlide($(".swiper1 .swiper-slide").eq(n), n);
4546
// swiper1.slideTo(n, 500, false);
4647
}
47-
}
48+
},
49+
opacityValue: 0.9
4850
}
4951
},
5052
computed: {
@@ -55,6 +57,9 @@ export default {
5557
return this.$refs.swiper2.swiper
5658
}
5759
},
60+
created () {
61+
window.addEventListener('scroll', this.getOpacityValue)
62+
},
5863
mounted () {
5964
// current swiper instance
6065
// 然后你就可以使用当前上下文内的swiper对象去做你想做的事了
@@ -65,6 +70,10 @@ export default {
6570
methods: {
6671
onFloorNav (index) {
6772
this.floorNavData.activeIndex = index
73+
},
74+
getOpacityValue () {
75+
let b = document.body.scrollTop / 550 || document.documentElement.scrollTop / 550
76+
this.opacityValue = b > 0.9 ? 0.9 : b
6877
}
6978
}
7079
}
@@ -76,4 +85,7 @@ export default {
7685
.is-active {
7786
border-bottom: 1px solid red;
7887
}
88+
.lorem {
89+
background: #d9241c;
90+
}
7991
</style>

src/page/home/home.vue

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<head-top signin-up='home'>
44
<span slot='logo' class="head_logo" @click="reload">ele.me</span>
55
</head-top>
6+
<button style="margin-top:100px" @click="goTest">去测试页面</button>
67
</div>
78
</template>
89
<script>
@@ -37,6 +38,7 @@ export default {
3738
sortgroupcity () {
3839
let sortobj = {}
3940
for (let i = 65; i <= 90; i++) {
41+
// 静态 String.fromCharCode() 方法返回使用指定的Unicode值序列创建的字符串。
4042
if (this.groupcity[String.fromCharCode(i)]) {
4143
sortobj[String.fromCharCode(i)] = this.groupcity[String.fromCharCode(i)]
4244
}
@@ -52,7 +54,11 @@ export default {
5254
},
5355
// 点击图标刷新页面
5456
reload () {
57+
// window.location 只读属性,返回一个 Location对象Location.reload() 方法用来刷新当前页面。该方法只有一个参数,当值为 true 时,将强制浏览器从服务器加载页面资源,当值为 false 或者未传参时,浏览器则可能从缓存中读取页面
5558
window.location.reload()
59+
},
60+
goTest () {
61+
this.$router.push('./test')
5662
}
5763
}
5864
}

0 commit comments

Comments
 (0)