Home.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. <!-- -->
  2. <template>
  3. <div class="Home" :class="{ last: topImgInd === 8 }">
  4. <!-- 顶部图片 -->
  5. <div class="topImg">
  6. <img :src="require(`@/assets/img/topImg/${topImgInd}.png`)" alt="" />
  7. </div>
  8. <!-- 中间内容---使用动态组件 -->
  9. <div class="main" :class="{ mainAc: myMenucShow }">
  10. <keep-alive>
  11. <component
  12. :scrool="scrool"
  13. v-if="topImgInd !== 1 && topImgInd !== 8"
  14. :is="`Son${topImgInd}`"
  15. ></component>
  16. </keep-alive>
  17. </div>
  18. <!-- 菜单图片 -->
  19. <div class="menu" @click="myMenucShow = true">
  20. <img src="../assets/img/menu.png" alt="" />
  21. </div>
  22. <!-- 底部菜单选择 -->
  23. <div class="bottom">
  24. <div
  25. class="row"
  26. @click="topImgInd = item.id"
  27. :class="{ active: topImgInd == item.id }"
  28. v-for="item in data"
  29. :key="item.id"
  30. >
  31. <div class="bs"></div>
  32. {{ item.name }}
  33. </div>
  34. </div>
  35. <!-- 下一章节 -->
  36. <div class="next" v-if="topImgInd < data.length" @click="topImgInd++">
  37. 下一章节
  38. </div>
  39. <!-- 卡片 -->
  40. <div class="myMenuc" :class="{ myMenucAc: myMenucShow }">
  41. <Menuc @upInfo="upInfo" />
  42. </div>
  43. </div>
  44. </template>
  45. <script>
  46. import Menuc from "./menuc/index.vue";
  47. import Son2 from "../components/son2.vue";
  48. import Son3 from "../components/son3.vue";
  49. import Son4 from "../components/son4.vue";
  50. import Son5 from "../components/son5.vue";
  51. import Son6 from "../components/son6.vue";
  52. import Son7 from "../components/son7.vue";
  53. export default {
  54. name: "Home",
  55. components: { Son2, Son3, Son4, Son5, Son6, Son7, Menuc },
  56. data() {
  57. //这里存放数据
  58. return {
  59. myMenucShow: false,
  60. data: [
  61. { id: 1, name: "序言" },
  62. { id: 2, name: "中西贸易" },
  63. { id: 3, name: "鸦片贸易" },
  64. { id: 4, name: "鸦片生产" },
  65. { id: 5, name: "鸦片祸害" },
  66. { id: 6, name: "林则徐禁烟" },
  67. { id: 7, name: "虎门销烟" },
  68. { id: 8, name: "结束语" },
  69. ],
  70. topImgInd: 1,
  71. // 内容动态组件的值
  72. scrool: 0,
  73. };
  74. },
  75. //监听属性 类似于data概念
  76. computed: {},
  77. //监控data中的数据变化
  78. watch: {
  79. topImgInd() {
  80. window.scrollTo({ top: 0 });
  81. },
  82. },
  83. //方法集合
  84. methods: {
  85. upInfo(id) {
  86. this.myMenucShow = false;
  87. this.topImgInd = id;
  88. if (id === this.topImgInd) window.scrollTo({ top: 0 });
  89. },
  90. },
  91. //生命周期 - 创建完成(可以访问当前this实例)
  92. created() {},
  93. //生命周期 - 挂载完成(可以访问DOM元素)
  94. mounted() {
  95. // 监听是否元素进入页面
  96. window.addEventListener("scroll", () => {
  97. this.scrool =
  98. document.documentElement.scrollTop ||
  99. window.pageYOffset ||
  100. document.body.scrollTop;
  101. // console.log(this.scrool);
  102. });
  103. },
  104. beforeCreate() {}, //生命周期 - 创建之前
  105. beforeMount() {}, //生命周期 - 挂载之前
  106. beforeUpdate() {}, //生命周期 - 更新之前
  107. updated() {}, //生命周期 - 更新之后
  108. beforeDestroy() {}, //生命周期 - 销毁之前
  109. destroyed() {}, //生命周期 - 销毁完成
  110. activated() {}, //如果页面有keep-alive缓存功能,这个函数会触发
  111. };
  112. </script>
  113. <style lang='less' scoped>
  114. .Home {
  115. padding-bottom: 30px;
  116. width: 100%;
  117. .topImg {
  118. width: 100%;
  119. img {
  120. width: 100%;
  121. vertical-align: middle;
  122. }
  123. }
  124. .main {
  125. overflow-x: hidden;
  126. background: url("../assets/img/bg.jpg");
  127. background-size: cover;
  128. opacity: 1;
  129. transition: opacity 0.5s;
  130. }
  131. .mainAc {
  132. opacity: 0;
  133. }
  134. .menu {
  135. position: fixed;
  136. width: 61px;
  137. height: 61px;
  138. right: 20px;
  139. bottom: 200px;
  140. & > img {
  141. width: 61px;
  142. }
  143. }
  144. .bottom {
  145. margin-top: 100px;
  146. display: flex;
  147. justify-content: space-around;
  148. background: url("../assets/img/line.png") top left no-repeat;
  149. background-size: 100% 2px;
  150. // border-top: 2px dashed #827d70;
  151. width: 100%;
  152. .row {
  153. position: relative;
  154. letter-spacing: 5px;
  155. padding-top: 15px;
  156. font-size: 14px;
  157. color: #827d70;
  158. writing-mode: vertical-lr;
  159. .bs {
  160. width: 14px;
  161. height: 14px;
  162. position: absolute;
  163. top: -6px;
  164. left: 0;
  165. &::before {
  166. content: "";
  167. border-radius: 50%;
  168. position: absolute;
  169. top: 50%;
  170. left: 50%;
  171. transform: translate(-50%, -50%);
  172. background-color: #827d70;
  173. width: 10px;
  174. height: 10px;
  175. }
  176. }
  177. }
  178. .active {
  179. color: #ebdfbf;
  180. pointer-events: none;
  181. .bs {
  182. left: 1px;
  183. border-radius: 50%;
  184. border: 1px solid #ebdfbf;
  185. &::before {
  186. width: 8px;
  187. height: 8px;
  188. background-color: #ebdfbf;
  189. }
  190. }
  191. }
  192. }
  193. .next {
  194. margin: 28px auto 0;
  195. width: 90px;
  196. padding-left: 30px;
  197. color: #c8b992;
  198. font-size: 14px;
  199. background: url("../assets/img/next.png") left center no-repeat;
  200. background-size: 20px 20px;
  201. }
  202. .myMenuc {
  203. transition: opacity 1s;
  204. z-index: 999;
  205. opacity: 0;
  206. background: url("../assets/img/bodyBac.jpg");
  207. pointer-events: none;
  208. position: fixed;
  209. width: 100vw;
  210. height: 100vh;
  211. top: 0;
  212. left: 0;
  213. }
  214. .myMenucAc {
  215. opacity: 1;
  216. pointer-events: auto;
  217. }
  218. }
  219. .last {
  220. padding-bottom: 80px;
  221. }
  222. </style>