|
@@ -1,19 +1,15 @@
|
|
|
<template>
|
|
|
<el-row class="mess">
|
|
|
- <el-col :span="24" class="bigImage" :class="{ 'new-style': isScrollingDown }"></el-col>
|
|
|
<el-col :span="24" class="info">
|
|
|
- <el-col :span="24" class="menus">
|
|
|
- <menusIndex />
|
|
|
- </el-col>
|
|
|
- <transition name="fade">
|
|
|
- <el-row v-if="isScrollingDown" class="new-title">
|
|
|
- <div class="title">{{ info.title }}</div>
|
|
|
- </el-row>
|
|
|
- </transition>
|
|
|
- <div ref="targetDiv" class="bottom">
|
|
|
- <el-col :span="24" class="zero top">
|
|
|
+ <el-col :span="24" class="top">
|
|
|
+ <el-col :span="24" class="menus" :class="{ new_style: y }">
|
|
|
+ <menusIndex />
|
|
|
+ </el-col>
|
|
|
+ <el-col :span="24" class="zero">
|
|
|
<top-index :info="info" />
|
|
|
</el-col>
|
|
|
+ </el-col>
|
|
|
+ <div class="bottom">
|
|
|
<el-col :span="24" class="zero">
|
|
|
<info-detail v-if="type === 'info'"></info-detail>
|
|
|
<water-detail v-else-if="type === 'water'"></water-detail>
|
|
@@ -35,8 +31,8 @@ import footIndex from '../../components/windows/footIndex.vue'
|
|
|
import infoDetail from './messParts/infoDetail.vue'
|
|
|
import waterDetail from './messParts/waterDetail.vue'
|
|
|
import serviceDetail from './messParts/serviceDetail.vue'
|
|
|
-import { get, throttle } from 'lodash-es'
|
|
|
-import { computed, onMounted, ref, onBeforeUnmount } from 'vue'
|
|
|
+import { get } from 'lodash-es'
|
|
|
+import { computed, onMounted, ref, onUnmounted } from 'vue'
|
|
|
import { useRoute } from 'vue-router'
|
|
|
const route = useRoute()
|
|
|
const type = computed(() => {
|
|
@@ -53,96 +49,60 @@ onMounted(() => {
|
|
|
}
|
|
|
})
|
|
|
|
|
|
-// 创建一个 ref 来引用目标 div
|
|
|
-const targetDiv = ref()
|
|
|
-// 用于存储是否向下滚动的状态
|
|
|
-const isScrollingDown = ref(false)
|
|
|
-// 滚动事件处理函数
|
|
|
-const handleScroll = () => {
|
|
|
- const currentScrollTop = targetDiv.value.scrollTop
|
|
|
-
|
|
|
- // 判断是否不在最上面且向下滚动
|
|
|
- if (currentScrollTop > 250) isScrollingDown.value = true
|
|
|
- else isScrollingDown.value = false
|
|
|
-}
|
|
|
+// 获取滚动条y轴坐标
|
|
|
+const { y } = useWindowScroll()
|
|
|
|
|
|
-// 创建节流后的滚动处理函数,每 200 毫秒触发一次
|
|
|
-const throttledScroll = throttle(handleScroll, 200)
|
|
|
+function useWindowScroll() {
|
|
|
+ const y = ref(0)
|
|
|
|
|
|
-onMounted(() => {
|
|
|
- // 组件挂载后,添加滚动事件监听器
|
|
|
- targetDiv.value.addEventListener('scroll', throttledScroll)
|
|
|
-})
|
|
|
+ const handleScroll = () => {
|
|
|
+ y.value = window.scrollY
|
|
|
+ }
|
|
|
|
|
|
-onBeforeUnmount(() => {
|
|
|
- // 组件卸载前,移除滚动事件监听器
|
|
|
- targetDiv.value.removeEventListener('scroll', throttledScroll)
|
|
|
-})
|
|
|
+ onMounted(() => {
|
|
|
+ window.addEventListener('scroll', handleScroll)
|
|
|
+ })
|
|
|
+
|
|
|
+ onUnmounted(() => {
|
|
|
+ window.removeEventListener('scroll', handleScroll)
|
|
|
+ })
|
|
|
+
|
|
|
+ return { y }
|
|
|
+}
|
|
|
</script>
|
|
|
|
|
|
<style scoped lang="scss">
|
|
|
.mess {
|
|
|
- position: relative;
|
|
|
-
|
|
|
- .bigImage {
|
|
|
- height: 480px;
|
|
|
- overflow: hidden;
|
|
|
- background-image: url('/water1.png');
|
|
|
- background-repeat: no-repeat;
|
|
|
- background-size: 100% 100%;
|
|
|
- }
|
|
|
-
|
|
|
- .new-style {
|
|
|
- height: 10em;
|
|
|
- width: 100%;
|
|
|
- top: 0;
|
|
|
- }
|
|
|
-
|
|
|
.info {
|
|
|
- position: absolute;
|
|
|
- top: 0;
|
|
|
- width: 100%;
|
|
|
- height: 100vh;
|
|
|
- overflow: hidden;
|
|
|
-
|
|
|
- .menus {
|
|
|
- height: 66px;
|
|
|
- overflow: hidden;
|
|
|
- }
|
|
|
-
|
|
|
- /* 定义淡入淡出过渡效果的 CSS 类 */
|
|
|
- .fade-enter-active,
|
|
|
- .fade-leave-active {
|
|
|
- transition: opacity 0.5s ease;
|
|
|
- }
|
|
|
+ .top {
|
|
|
+ height: 480px;
|
|
|
+ background-image: url('/water1.png');
|
|
|
+ background-repeat: no-repeat;
|
|
|
+ background-size: 100% 100%;
|
|
|
+ .menus {
|
|
|
+ height: 66px;
|
|
|
+ }
|
|
|
|
|
|
- .fade-enter-from,
|
|
|
- .fade-leave-to {
|
|
|
- opacity: 0;
|
|
|
- }
|
|
|
- .new-title {
|
|
|
- display: flex;
|
|
|
- padding: 0 17%;
|
|
|
- color: rgb(25, 25, 26);
|
|
|
- font-family: '宋体';
|
|
|
- font-size: 40px;
|
|
|
- font-weight: 700;
|
|
|
- line-height: 90px;
|
|
|
- letter-spacing: 8px;
|
|
|
+ .new_style {
|
|
|
+ position: fixed;
|
|
|
+ left: 0;
|
|
|
+ top: 0;
|
|
|
+ width: 100%;
|
|
|
+ z-index: 1000;
|
|
|
+ background-color: #fff;
|
|
|
+ -webkit-transition: all 0.8s ease;
|
|
|
+ transition: all 0.8s ease;
|
|
|
+ }
|
|
|
+ .zero {
|
|
|
+ padding: 0 17%;
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
.bottom {
|
|
|
- height: calc(100vh - 66px);
|
|
|
- overflow-y: auto;
|
|
|
- margin: 0 auto;
|
|
|
-
|
|
|
+ margin: 40px 0 0 0;
|
|
|
.zero {
|
|
|
margin: 0 0 40px 0;
|
|
|
}
|
|
|
-
|
|
|
- .top {
|
|
|
- padding: 0 17%;
|
|
|
- }
|
|
|
}
|
|
|
}
|
|
|
}
|