【生活美好】Mobile-H5-web-for-vue

各位亲爱的程序员们好,本宝宝又开始上github啦
和各位程序员宝宝们一起努力呢
话不多说,先上这个项目的效果
【生活美好】Mobile-H5-web-for-vue
这个项目应该就是那种H5项目,不过是用vue写的
放上github地址:https://github.com/ihopefulChina/Mobile-H5-web-for-vue
我们一起看代码啦
看了下package.json里面用到的插件不多

{
  "name": "test1",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "serve": "vue-cli-service serve",
    "build": "vue-cli-service build"
  },
  "dependencies": {
    "core-js": "^3.6.4",
    "jquery": "^3.5.1",
    "swiper": "^5.3.8",
    "vue": "^2.6.11",
    "vue-awesome-swiper": "^4.1.1",
    "vue-directive-touch": "^1.0.28",
    "vue-router": "^3.1.6",
    "vuex": "^3.1.3"
  },
  "devDependencies": {
    "@vue/cli-plugin-babel": "~4.3.0",
    "@vue/cli-plugin-router": "~4.3.0",
    "@vue/cli-plugin-vuex": "~4.3.0",
    "@vue/cli-service": "~4.3.0",
    "less": "^3.0.4",
    "less-loader": "^5.0.0",
    "vue-template-compiler": "^2.6.11"
  },
  "browserslist": [
    "> 1%",
    "last 2 versions",
    "not dead"
  ]
}

//main.js
import Vue from "vue";
import App from "./App.vue";
import router from "./router";
import store from "./store";

import touch from 'vue-directive-touch';
Vue.use(touch);

// import Loading from '@/components/Loading'
// Vue.component('Loading', Loading);

Vue.config.productionTip = false

new Vue({
  router,
  store,
  render: (h) => h(App),
}).$mount("#app");

main.js中就是入口引用了相关的组件

//app.vue
<template>
  <div id="app">
    <router-view />
  </div>
</template>

<style lang="less">
#app {
  height: 100%;
  position: absolute;
  left: 0;
  right: 0;
  margin: auto;
}
</style>

接下来看router.js
默认是进入Home页面,Home页面里面有两个入口

import Vue from "vue";
import VueRouter from "vue-router";
import Home from "../views/Home";
Vue.use(VueRouter);

const routes = [{
    path: "/",
    name: "Home",
    component: Home,
  },
  {
    path: "/page1/",
    name: "Page1",
    component: () => import("@/views/Page1"),
    children: [{
        path: "pth",
        component: () => import("@/components/Page/Pth/"),
      },
      {
        path: "njh",
        component: () => import("@/components/Page/Njh/"),
      },
    ],
  },
  {
    path: "/page2/",
    name: "Page2",
    component: () => import("@/views/Page2"),
  },
  {
    path: "/page3/",
    name: "Page3",
    component: () => import("@/views/Page3"),
  },
];

const router = new VueRouter({
  mode: "history",
  base: process.env.BASE_URL,
  routes,
});

export default router;

接下来我们看home.vue页面
home.vue中包含了三个入口

//home.vue
<template>
  <div id="main">
    <Loading />
    <div class="home-page-box" v-touch:up="onSwipeUp">
      <transition>
        <router-view></router-view>
      </transition>
      <Bgm />
      <div class="page-warp home-page"></div>
      <div class="home-img home-logo">
        <img src="@/assets/img/p101.png" alt="p101" />
      </div>
      <div class="home-btn">
        <div class="home-group-box">
          <router-link tag="div" to="/page1/njh" class="home-img">
            <img src="@/assets/img/img01.png" alt="img01" />
            <div class="home-handle">
              <img src="@/assets/img/shou.png" alt="shou" />
            </div>
          </router-link>
          <router-link tag="div" to="/page1/pth" class="home-img">
            <img src="@/assets/img/img02.png" alt="img02" />
            <div class="home-handle">
              <img src="@/assets/img/shou.png" alt="shou 2" />
            </div>
          </router-link>
        </div>
      </div>
      <div class="home-content">
        <div class="home-group-box">
          <div class="home-img">
            <img src="@/assets/img/img03.png" alt="img03" />
          </div>
          <div class="home-img">
            <img src="@/assets/img/img04.png" alt="img04" />
          </div>
          <div class="home-img">
            <img src="@/assets/img/img05.png" alt="img05" />
          </div>
          <div class="home-img">
            <img src="@/assets/img/img06.png" alt="img06" />
          </div>
          <div class="home-img">
            <img src="@/assets/img/img07.png" alt="img07" />
          </div>
          <div class="home-img">
            <img src="@/assets/img/img08.png" alt="img08" />
          </div>
          <div class="home-img">
            <img src="@/assets/img/img09.png" alt="img09" />
          </div>
          <div class="home-img">
            <img src="@/assets/img/img0a.png" alt="img0a" />
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import Bgm from "@/components/Bgm";
import Loading from "@/components/Loading";
export default {
  name: "Home",
  data() {
    return {
      isloading: false,
    };
  },
  components: {
    Bgm,
    Loading,
  },
  methods: {
    onSwipeUp() {
      this.$router.go(-1);
    },
  },
};
</script>

<style scoped lang="less">
#main {
  width: 100%;
  height: 100%;
  .page-warp {
    position: absolute;
    width: 100%;
    height: 100%;
    overflow: hidden;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    -webkit-backface-visibility: visible;
    backface-visibility: visible;
    background-repeat: no-repeat;
    background-size: cover;
    touch-action: none;
    user-select: none;
    -webkit-user-drag: none;
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
    .page-warp {
      width: 100%;
      min-height: 100%;
      position: relative;
    }
  }
  .home-page {
    background-image: url("~@/assets/img/bg.png");
  }
  .home-page-box {
    width: 100%;
    min-height: 100%;
    position: relative;
    .home-img {
      background-size: cover;
      background-position: 50%;
      animation: puffIn 1000ms 2100ms both;
      position: absolute;
      left: 0;
      right: 0;
      img {
        width: 100%;
        height: auto;
        pointer-events: none;
        display: none;
      }
    }
    .home-logo {
      bottom: 0.44rem;
      height: auto;
      width: 6.688rem;
      margin: auto;
      img {
        display: block;
      }
    }
    .home-btn {
      background-size: cover;
      height: 1.792rem;
      left: 4.928rem;
      top: 31.768rem;
      width: 14.144rem;
      position: absolute;
      .home-group-box {
        width: 100%;
        min-height: 100%;
        position: relative;
        .home-img {
          background-size: cover;
          background-position: 50%;
          img {
            width: 100%;
            pointer-events: none;
            display: block;
          }
          .home-handle {
            position: absolute;
            right: 0;
            left: 0;
            top: 1rem;
            margin: 0 auto;
            width: 2rem;
            animation: fadeIn 1000ms 1800ms both;
            img {
              -webkit-animation: twinkling 0.6s infinite ease-in-out;
              animation: twinkling 0.6s infinite ease-in-out;
            }
          }
        }
        .home-img:nth-child(1) {
          animation: fadeInUp 1000ms 1800ms both;
          height: 1.792rem;
          left: 8rem;
          position: absolute;
          top: 0;
          width: 6.144rem;
        }
        .home-img:nth-child(2) {
          animation: fadeInUp 1000ms 1600ms both;
          height: 1.792rem;
          left: 0;
          position: absolute;
          top: 0;
          width: 6.176rem;
        }
      }
    }
    .home-content {
      height: 29.92rem;
      left: 1.728rem;
      position: absolute;
      top: 1.696rem;
      width: 17.28rem;
      .home-group-box {
        width: 100%;
        min-height: 100%;
        position: relative;
        .home-img {
          background-size: cover;
          background-position: 50%;
          img {
            width: 100%;
            pointer-events: none;
            display: block;
          }
        }
        .home-img:nth-child(1) {
          animation: fadeInLeft 1000ms 100ms both;
          height: 7.904rem;
          left: 3.264rem;
          position: absolute;
          top: 18.208rem;
          width: 14.016rem;
        }
        .home-img:nth-child(2) {
          animation: fadeInRight 1000ms 100ms both;
          height: 16rem;
          left: 3.264rem;
          position: absolute;
          top: 1.952rem;
          width: 14.016rem;
        }
        .home-img:nth-child(3) {
          animation: puffIn 1000ms 1000ms both;
          height: 6.24rem;
          left: 4.352rem;
          position: absolute;
          top: 22.016rem;
          width: 11.52rem;
        }
        .home-img:nth-child(4) {
          animation: fadeIn 1000ms 300ms both;
          height: 1.376rem;
          left: 1.152rem;
          position: absolute;
          top: 0;
          width: 2.688rem;
        }
        .home-img:nth-child(5) {
          animation: fadeIn 1000ms 700ms both;
          height: 3.072rem;
          left: 0;
          position: absolute;
          top: 18.208rem;
          width: 3.296rem;
        }
        .home-img:nth-child(6) {
          animation: fadeIn 1000ms 600ms both;
          height: 8.16rem;
          left: 1.216rem;
          position: absolute;
          top: 8.672rem;
          width: 1.056rem;
        }
        .home-img:nth-child(7) {
          animation: fadeInLeft 1000ms 1300ms both;
          height: 1.984rem;
          left: 10.944rem;
          position: absolute;
          top: 27.904rem;
          width: 4.896rem;
        }
        .home-img:nth-child(8) {
          animation: fadeInRight 1000ms 1300ms both;
          height: 2.112rem;
          left: 4.672rem;
          position: absolute;
          top: 27.808rem;
          width: 5.472rem;
        }
      }
    }
  }
}
.animated {
  -webkit-animation-duration: 1s;
  animation-duration: 1s;
  -webkit-animation-fill-mode: both;
  animation-fill-mode: both;
}
@-webkit-keyframes twinkling {
  0% {
    opacity: 0;
  }
  100% {
    opacity: 1;
  }
}
@keyframes twinkling {
  0% {
    opacity: 0;
  }
  100% {
    opacity: 1;
  }
}
</style>

home.vue中还引用了Bgm组件和loading组件
接下来看Loading组件
这个loading组件是作者自己封装的呢

//loading.vue
<template>
  <div class="loader">
    <img src="@/assets/img/p101.png" alt="laoding-logo" />
    <div class="loading">
      <i></i>
      <i></i>
      <i></i>
      <i></i>
      <i></i>
    </div>
  </div>
</template>
<script>
export default {
  name: "Loading",
};
</script>

<style lang="less" scoped>
html,
body {
  height: 100%;
}

.loader {
  position: absolute;
  width: 100%;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  margin: 0 auto;
  img {
    width: 8rem;
    height: auto;
  }

  .loading {
    margin-top: 2rem;
    i {
      display: inline-block;
      width: 4px;
      height: 2rem;
      border-radius: 2px;
      margin: 0 2px;
      background-color: #333;
    }
    i:nth-child(1) {
      animation: loading 0.5s ease-in 0.1s infinite;
    }
    i:nth-child(2) {
      animation: loading 0.5s ease-in 0.2s infinite;
    }
    i:nth-child(3) {
      animation: loading 0.5s ease-in 0.3s infinite;
    }
    i:nth-child(4) {
      animation: loading 0.5s ease-in 0.4s infinite;
    }
    i:nth-child(5) {
      animation: loading 0.5s ease-in 0.5s infinite;
    }
  }
  @keyframes loading {
    0% {
      transform: scaleY(1);
    }
    50% {
      transform: scaleY(0.4);
    }
    100% {
      transform: scaleY(1);
    }
  }
}
</style>

接下来是背景音乐组件,也是作者自己封装的
有意思极了,这个地方为啥是用的dom不是用的vue语法,神奇,不过代码很有意思

<template>
  <div id="bg_music">
    <div id="audio-btn" @click="changeOn" :class="isOff ? 'off' : 'on'">
      <audio src="@/assets/music.mp3" id="media" autoplay></audio>
    </div>
  </div>
</template>
<script>
export default {
  name: "hello",
  data() {
    return {
      isOff: false,
    };
  },
  mounted() {
    // 自动播放音乐效果,解决微信自动播放问题
    document.addEventListener("touchstart", this.audioAutoPlay, false);
    document.addEventListener("WeixinJSBridgeReady", this.audioAutoPlay, false);
    let oAudio = document.querySelector("#media");
    oAudio.onended = function() {
      //播放完毕,重新循环播放
      oAudio.load();
      oAudio.play();
    };
  },
  methods: {
    changeOn() {
      let oAudio = document.querySelector("#media");
      oAudio.pause();
      if (this.isOff) {
        oAudio.play(); //让音频文件开始播放
      } else {
        oAudio.pause(); //让音频文件暂停播放
      }
      this.isOff = !this.isOff;
    },
    audioAutoPlay() {
      let audio = document.getElementById("media");
      this.isOff = false;
      audio.play();
      document.removeEventListener("touchstart", this.audioAutoPlay);
    },
  },
};
</script>

<style lang="less" scoped>
#bg_music {
  position: absolute;
  z-index: 1992;
  display: block;
  width: 28px;
  height: 28px;
  top: 10px;
  right: 10px;
  #audio-btn {
    width: 100%;
    height: 100%;
    background-size: 100% 100%;
  }
  .on {
    background: url("~@/assets/img/playing_1.svg") no-repeat 0 0;
    -webkit-animation: rotating 1.2s linear infinite;
    animation: rotating 1.2s linear infinite;
  }
  .off {
    background: url("~@/assets/img/paused_18.svg") no-repeat 0 0;
  }
}
@-webkit-keyframes rotating {
  from {
    -webkit-transform: rotate(0deg);
    -moz-transform: rotate(0deg);
    -ms-transform: rotate(0deg);
    -o-transform: rotate(0deg);
    transform: rotate(0deg);
  }
  to {
    -webkit-transform: rotate(360deg);
    -moz-transform: rotate(360deg);
    -ms-transform: rotate(360deg);
    -o-transform: rotate(360deg);
    transform: rotate(360deg);
  }
}
@keyframes rotating {
  from {
    -webkit-transform: rotate(0deg);
    -moz-transform: rotate(0deg);
    -ms-transform: rotate(0deg);
    -o-transform: rotate(0deg);
    transform: rotate(0deg);
  }
  to {
    -webkit-transform: rotate(360deg);
    -moz-transform: rotate(360deg);
    -ms-transform: rotate(360deg);
    -o-transform: rotate(360deg);
    transform: rotate(360deg);
  }
}
</style>

接下来是南京话里面的模块

//Njh.vue
<template>
  <div
    id="main"
    v-touch:up="onSwipeUp"
    v-touch:down="onSwipeDowm"
    v-touch:left="onSwipeUp"
    v-touch:right="onSwipeDowm"
  >
    <transition>
      <router-view></router-view>
    </transition>
    <div id="bg_music">
      <div id="audio-btn" @click="changeOn" :class="isOff ? 'off' : 'on'">
        <audio src="@/assets/music.mp3" id="media" autoplay></audio>
      </div>
    </div>
    <div class="page-warp page1-bg"></div>
    <div class="page1-page-box">
      <div class="page1-group page1-content">
        <div class="page1-group-box">
          <router-link tag="div" to="/page1/pth" class="page1-group page1-btn">
            <div class="page1-group-box">
              <div class="page1-img">
                <img src="@/assets/img/img02.png" alt="img01" />
              </div>
            </div>
          </router-link>
          <div class="page1-img page1-fz-content">
            <img src="@/assets/img/img0b.png" alt="img0b" />
          </div>
          <div class="rulediv">
            <img
              :src="require('@/assets/img/b' + ruleimg + '.png')"
              class="sizeimg"
            />
            <audio
              :src="require('@/assets/mp3/p1-' + ruleimg + '.mp3')"
              class="media audio"
              ref="audio"
            ></audio>
          </div>
          <div class="page1-group page1-click-btn">
            <div class="page1-group-box">
              <div
                class="page1-group"
                v-for="(item, index) in items"
                :key="index"
                @click="changeOnVice(item)"
                :class="item.ids == num ? 'active' : ''"
              >
                <div class="page1-group-box">
                  <div class="page1-img" ref="pageImgBtns">
                    <img
                      class="pageImgBtns"
                      :src="
                        item.ids == num
                          ? require('@/assets/img/img0' + item.url + '.gif')
                          : require('@/assets/img/img0' + item.url + '.png')
                      "
                      alt="img"
                    />
                  </div>
                </div>
              </div>
            </div>
          </div>
          <div class="page1-img page1-click-voice">
            <img src="@/assets/img/img0j.png" alt="img0j" />
          </div>
          <div class="page1-img page1-click-handle">
            <img src="@/assets/img/img0k.png" alt="img0k" />
          </div>
        </div>
      </div>
      <div class="page1-img-content page1-img">
        <img src="@/assets/img/p201.png" alt="p201" />
      </div>
      <div class="page1-img-content page1-img">
        <img src="@/assets/img/img0l.png" alt="img0l" />
      </div>
      <div class="page1-img-content page1-img">
        <img src="@/assets/img/img0m.png" alt="img0m" />
      </div>
    </div>
    <router-link class="swiper-next" tag="div" to="/page2/">
      <div class="page-arrow">
        <img src="@/assets/img/arrow.png" alt="arrow" />
      </div>
    </router-link>
  </div>
</template>
<script>
import Bgm from "@/components/Bgm";
export default {
  name: "Njh",
  data() {
    return {
      num: -1,
      items: [
        { pid: "7", url: "c", ids: 1 },
        { pid: "6", url: "d", ids: 2 },
        { pid: "5", url: "e", ids: 3 },
        { pid: "3", url: "f", ids: 4 },
        { pid: "4", url: "g", ids: 5 },
        { pid: "1", url: "i", ids: 6 },
      ],
      ruleimg: "1",
      isOff: false,
    };
  },
  mounted() {
    // 自动播放音乐效果,解决微信自动播放问题
    document.addEventListener("touchstart", this.audioAutoPlay, false);
    document.addEventListener("WeixinJSBridgeReady", this.audioAutoPlay, false);
    let oAudio = document.querySelector("#media");
    oAudio.onended = function() {
      //播放完毕,重新循环播放
      oAudio.load();
      oAudio.play();
    };
  },
  components: {
    Bgm,
  },
  methods: {
    changeOn() {
      let oAudio = document.querySelector("#media");
      oAudio.pause();
      if (this.isOff) {
        oAudio.play(); //让音频文件开始播放
      } else {
        oAudio.pause(); //让音频文件暂停播放
      }
      this.isOff = !this.isOff;
    },
    audioAutoPlay() {
      let audio = document.getElementById("media");
      this.isOff = false;
      audio.play();
      document.removeEventListener("touchstart", this.audioAutoPlay);
    },
    changeOnVice(item) {
      //显示介绍图片
      let sizeimg = document.querySelector(".sizeimg");
      sizeimg.style.display = "block";
      let media = document.querySelector(".media");
      return (this.ruleimg = item.pid), (this.num = item.ids), media.play();
    },
    onSwipeUp() {
      this.$router.push("/page2");
    },
    onSwipeDowm() {
      this.$router.push("/");
    },
  },
};
</script>
<style scoped lang="less">
#bg_music {
  position: absolute;
  z-index: 1992;
  display: block;
  width: 28px;
  height: 28px;
  top: 10px;
  right: 10px;
  #audio-btn {
    width: 100%;
    height: 100%;
    background-size: 100% 100%;
  }
  .on {
    background: url("~@/assets/img/playing_1.svg") no-repeat 0 0;
    -webkit-animation: rotating 1.2s linear infinite;
    animation: rotating 1.2s linear infinite;
  }
  .off {
    background: url("~@/assets/img/paused_18.svg") no-repeat 0 0;
  }
}
@-webkit-keyframes rotating {
  from {
    -webkit-transform: rotate(0deg);
    -moz-transform: rotate(0deg);
    -ms-transform: rotate(0deg);
    -o-transform: rotate(0deg);
    transform: rotate(0deg);
  }
  to {
    -webkit-transform: rotate(360deg);
    -moz-transform: rotate(360deg);
    -ms-transform: rotate(360deg);
    -o-transform: rotate(360deg);
    transform: rotate(360deg);
  }
}
@keyframes rotating {
  from {
    -webkit-transform: rotate(0deg);
    -moz-transform: rotate(0deg);
    -ms-transform: rotate(0deg);
    -o-transform: rotate(0deg);
    transform: rotate(0deg);
  }
  to {
    -webkit-transform: rotate(360deg);
    -moz-transform: rotate(360deg);
    -ms-transform: rotate(360deg);
    -o-transform: rotate(360deg);
    transform: rotate(360deg);
  }
}
.page1-bg {
  background-image: url("~@/assets/img/bg01.png");
}
.page1-page-box {
  width: 100%;
  min-height: 100%;
  position: relative;
  .page-img {
    background-size: cover;
    background-position: 50%;
    img {
      width: 100%;
      pointer-events: none;
      display: block;
    }
  }
  .page1-group {
    background-size: cover;
    .page1-group-box {
      width: 100%;
      min-height: 100%;
      position: relative;
    }
  }
  .page1-content {
    height: 22.24rem;
    left: 2.848rem;
    position: absolute;
    top: 10.912rem;
    width: 18.976rem;
  }
  .page1-btn {
    animation: fadeInUp 1000ms 2000ms both;
    position: absolute;
    left: 6.5rem;
    top: 22.5rem;
    width: 6.2rem;
    height: 2rem;
    z-index: 999;
    .page1-group-box {
      .page1-img:nth-child(1) {
        height: 1.792rem;
        left: 0rem;
        position: absolute;
        bottom: 0rem;
        width: 6.144rem;
      }
      .page1-img:nth-child(2) {
        height: 1.792rem;
        left: 0rem;
        position: absolute;
        bottom: 0rem;
        width: 6.144rem;
      }
    }
  }
  .page1-img {
    background-size: cover;
    background-position: 50%;
    img {
      width: 100%;
      pointer-events: none;
      display: block;
    }
  }
  .page1-fz-content {
    animation: puffIn 1000ms 300ms both;
    height: 19.232rem;
    left: 0;
    position: absolute;
    top: 0;
    width: 18.304rem;
  }
  .rulediv {
    position: absolute;
    left: 0;
    top: 0;
    width: 52%;
    z-index: 999;

    .sizeimg {
      display: none;
      position: absolute;
      left: 0;
      top: 0;
      width: 100%;
    }
  }
  .rulediv.active {
    display: block;
  }
  .page1-click-btn {
    height: 17.088rem;
    left: 1.216rem;
    position: absolute;
    top: 1.248rem;
    width: 17.76rem;
    .page1-group.active {
      .page1-img {
        animation: fadeIn 1000ms 0ms both;
        transform: scale3d(1.5, 1.5, 1.5);
      }
    }
    .page1-group:nth-child(1) {
      animation: fadeIn 1000ms 1400ms both;
      height: 1.536rem;
      left: 11.584rem;
      position: absolute;
      top: 15.552rem;
      width: 4.48rem;
      .page1-img {
        height: 1.536rem;
        left: 0;
        position: absolute;
        top: 0;
        width: 4.48rem;
      }
    }
    .page1-group:nth-child(2) {
      animation: fadeIn 1000ms 900ms both;
      height: 1.536rem;
      left: 0;
      position: absolute;
      top: 13.056rem;
      width: 4.448rem;
      .page1-img {
        height: 1.536rem;
        left: 0;
        position: absolute;
        top: 0;
        width: 4.448rem;
      }
    }
    .page1-group:nth-child(3) {
      animation: fadeIn 1000ms 1600ms both;
      height: 1.536rem;
      left: 4.576rem;
      position: absolute;
      top: 9.376rem;
      width: 4.448rem;
      .page1-img {
        height: 1.536rem;
        left: 0;
        position: absolute;
        top: 0;
        width: 4.448rem;
      }
    }
    .page1-group:nth-child(4) {
      animation: fadeIn 1000ms 1100ms both;
      height: 1.536rem;
      left: 11.488rem;
      position: absolute;
      top: 10.496rem;
      width: 4.48rem;
      .page1-img {
        height: 1.536rem;
        left: 0;
        position: absolute;
        top: 0;
        width: 4.48rem;
      }
    }
    .page1-group:nth-child(5) {
      animation: fadeIn 1000ms 1000ms both;
      height: 1.536rem;
      left: 0.16rem;
      position: absolute;
      top: 2.656rem;
      width: 4.48rem;
      .page1-img {
        height: 1.536rem;
        left: 0;
        position: absolute;
        top: 0;
        width: 4.48rem;
      }
    }
    .page1-group:nth-child(6) {
      animation: fadeIn 1000ms 1300ms both;
      height: 1.536rem;
      left: 13.28rem;
      position: absolute;
      top: 2.656rem;
      width: 4.48rem;
      .page1-img {
        height: 1.536rem;
        left: 0;
        position: absolute;
        top: 0;
        width: 4.48rem;
      }
    }
    .page1-group:nth-child(7) {
      animation: fadeIn 1000ms 1700ms both;
      height: 1.536rem;
      left: 10.912rem;
      position: absolute;
      top: 0;
      width: 4.48rem;
      .page1-img {
        height: 1.536rem;
        left: 0;
        position: absolute;
        top: 0;
        width: 4.48rem;
      }
    }
  }
  .page1-click-voice {
    animation: fadeIn 1000ms 1900ms both;
    height: 1.536rem;
    left: 3.296rem;
    position: absolute;
    top: 20.704rem;
    width: 11.68rem;
  }
  .page1-click-handle {
    animation: fadeIn 1000ms 1900ms both;
    height: 1.088rem;
    left: 4.096rem;
    position: absolute;
    top: 20.832rem;
    width: 0.672rem;
    img {
      -webkit-animation: twinkling 0.6s infinite ease-in-out;
      animation: twinkling 0.6s infinite ease-in-out;
    }
  }
  .page1-img-content:nth-child(2) {
    animation: fadeInUp 1000ms 2200ms both;
    bottom: 1.528rem;
    height: 2.912rem;
    left: 4.032rem;
    position: absolute;
    width: 16.896rem;
  }
  .page1-img-content:nth-child(3) {
    animation: fadeInRight 1000ms 100ms both;
    height: 4.8rem;
    left: 12rem;
    position: absolute;
    top: 2.528rem;
    width: 5.088rem;
  }
  .page1-img-content:nth-child(4) {
    animation: fadeInLeft 1000ms 100ms both;
    height: 4.8rem;
    left: 6.912rem;
    position: absolute;
    top: 2.528rem;
    width: 5.056rem;
  }
}
</style>

普通话中的模块是类似的

//Pth
<template>
  <div
    id="main"
    v-touch:up="onSwipeUp"
    v-touch:down="onSwipeDowm"
    v-touch:left="onSwipeUp"
    v-touch:right="onSwipeDowm"
  >
    <transition>
      <router-view></router-view>
    </transition>
    <div id="bg_music">
      <div id="audio-btn" @click="changeOn" :class="isOff ? 'off' : 'on'">
        <audio src="@/assets/music.mp3" id="media" autoplay></audio>
      </div>
    </div>
    <div class="page-warp page1-bg"></div>
    <div class="page1-page-box">
      <div class="page1-group page1-content">
        <div class="page1-group-box">
          <router-link tag="div" to="/page1/njh" class="page1-group page1-btn">
            <div class="page1-group-box">
              <div class="page1-img">
                <img src="@/assets/img/img01.png" alt="img01" />
              </div>
            </div>
          </router-link>
          <div class="page1-img page1-fz-content">
            <img src="@/assets/img/img0b.png" alt="img0b" />
          </div>
          <div class="rulediv">
            <img
              :src="require('@/assets/img/b' + ruleimg + '.png')"
              class="sizeimg"
            />
            <audio
              :src="require('@/assets/mp3/p2-' + ruleimg + '.mp3')"
              class="media audio"
              ref="audio"
            ></audio>
          </div>
          <div class="page1-group page1-click-btn">
            <div class="page1-group-box">
              <div
                class="page1-group"
                v-for="(item, index) in items"
                :key="index"
                @click="changeOnVice(item)"
                :class="item.ids == num ? 'active' : ''"
              >
                <div class="page1-group-box">
                  <div class="page1-img" ref="pageImgBtns">
                    <img
                      class="pageImgBtns"
                      :src="
                        item.ids == num
                          ? require('@/assets/img/img0' + item.url + '.gif')
                          : require('@/assets/img/img0' + item.url + '.png')
                      "
                      alt="img"
                    />
                  </div>
                </div>
              </div>
            </div>
          </div>
          <div class="page1-img page1-click-voice">
            <img src="@/assets/img/img0j.png" alt="img0j" />
          </div>
          <div class="page1-img page1-click-handle">
            <img src="@/assets/img/img0k.png" alt="img0k" />
          </div>
        </div>
      </div>
      <div class="page1-img-content page1-img">
        <img src="@/assets/img/p201.png" alt="p201" />
      </div>
      <div class="page1-img-content page1-img">
        <img src="@/assets/img/img0l.png" alt="img0l" />
      </div>
      <div class="page1-img-content page1-img">
        <img src="@/assets/img/img0m.png" alt="img0m" />
      </div>
    </div>
    <router-link class="swiper-next" tag="div" to="/page2/">
      <div class="page-arrow">
        <img src="@/assets/img/arrow.png" alt="arrow" />
      </div>
    </router-link>
  </div>
</template>
<script>
import Bgm from "@/components/Bgm";
export default {
  name: "Njh",
  data() {
    return {
      num: -1,
      items: [
        { pid: "7", url: "c", ids: 1 },
        { pid: "6", url: "d", ids: 2 },
        { pid: "5", url: "e", ids: 3 },
        { pid: "3", url: "f", ids: 4 },
        { pid: "4", url: "g", ids: 5 },
        { pid: "1", url: "i", ids: 6 },
      ],
      ruleimg: "1",
      isOff: false,
    };
  },
  mounted() {
    // 自动播放音乐效果,解决微信自动播放问题
    document.addEventListener("touchstart", this.audioAutoPlay, false);
    document.addEventListener("WeixinJSBridgeReady", this.audioAutoPlay, false);
    let oAudio = document.querySelector("#media");
    oAudio.onended = function() {
      //播放完毕,重新循环播放
      oAudio.load();
      oAudio.play();
    };
  },
  components: {
    Bgm,
  },
  methods: {
    changeOn() {
      let oAudio = document.querySelector("#media");
      oAudio.pause();
      if (this.isOff) {
        oAudio.play(); //让音频文件开始播放
      } else {
        oAudio.pause(); //让音频文件暂停播放
      }
      this.isOff = !this.isOff;
    },
    audioAutoPlay() {
      let audio = document.getElementById("media");
      this.isOff = false;
      audio.play();
      document.removeEventListener("touchstart", this.audioAutoPlay);
    },
    changeOnVice(item) {
      //显示介绍图片
      let sizeimg = document.querySelector(".sizeimg");
      sizeimg.style.display = "block";
      let media = document.querySelector(".media");
      return (this.ruleimg = item.pid), (this.num = item.ids), media.play();
    },
    onSwipeUp() {
      this.$router.push("/page2");
    },
    onSwipeDowm() {
      this.$router.push("/");
    },
  },
};
</script>
<style scoped lang="less">
#bg_music {
  position: absolute;
  z-index: 1992;
  display: block;
  width: 28px;
  height: 28px;
  top: 10px;
  right: 10px;
  #audio-btn {
    width: 100%;
    height: 100%;
    background-size: 100% 100%;
  }
  .on {
    background: url("~@/assets/img/playing_1.svg") no-repeat 0 0;
    -webkit-animation: rotating 1.2s linear infinite;
    animation: rotating 1.2s linear infinite;
  }
  .off {
    background: url("~@/assets/img/paused_18.svg") no-repeat 0 0;
  }
}
@-webkit-keyframes rotating {
  from {
    -webkit-transform: rotate(0deg);
    -moz-transform: rotate(0deg);
    -ms-transform: rotate(0deg);
    -o-transform: rotate(0deg);
    transform: rotate(0deg);
  }
  to {
    -webkit-transform: rotate(360deg);
    -moz-transform: rotate(360deg);
    -ms-transform: rotate(360deg);
    -o-transform: rotate(360deg);
    transform: rotate(360deg);
  }
}
@keyframes rotating {
  from {
    -webkit-transform: rotate(0deg);
    -moz-transform: rotate(0deg);
    -ms-transform: rotate(0deg);
    -o-transform: rotate(0deg);
    transform: rotate(0deg);
  }
  to {
    -webkit-transform: rotate(360deg);
    -moz-transform: rotate(360deg);
    -ms-transform: rotate(360deg);
    -o-transform: rotate(360deg);
    transform: rotate(360deg);
  }
}
.page1-bg {
  background-image: url("~@/assets/img/bg01.png");
}
.page1-page-box {
  width: 100%;
  min-height: 100%;
  position: relative;
  .page-img {
    background-size: cover;
    background-position: 50%;
    img {
      width: 100%;
      pointer-events: none;
      display: block;
    }
  }
  .page1-group {
    background-size: cover;
    .page1-group-box {
      width: 100%;
      min-height: 100%;
      position: relative;
    }
  }
  .page1-content {
    height: 22.24rem;
    left: 2.848rem;
    position: absolute;
    top: 10.912rem;
    width: 18.976rem;
  }
  .page1-btn {
    animation: fadeInUp 1000ms 2000ms both;
    position: absolute;
    left: 6.5rem;
    top: 22.5rem;
    width: 6.2rem;
    height: 2rem;
    z-index: 999;
    .page1-group-box {
      .page1-img:nth-child(1) {
        height: 1.792rem;
        left: 0rem;
        position: absolute;
        bottom: 0rem;
        width: 6.144rem;
      }
      .page1-img:nth-child(2) {
        height: 1.792rem;
        left: 0rem;
        position: absolute;
        bottom: 0rem;
        width: 6.144rem;
      }
    }
  }
  .page1-img {
    background-size: cover;
    background-position: 50%;
    img {
      width: 100%;
      pointer-events: none;
      display: block;
    }
  }
  .page1-fz-content {
    animation: puffIn 1000ms 300ms both;
    height: 19.232rem;
    left: 0;
    position: absolute;
    top: 0;
    width: 18.304rem;
  }
  .rulediv {
    position: absolute;
    left: 0;
    top: 0;
    width: 52%;
    z-index: 999;

    .sizeimg {
      display: none;
      position: absolute;
      left: 0;
      top: 0;
      width: 100%;
    }
  }
  .rulediv.active {
    display: block;
  }
  .page1-click-btn {
    height: 17.088rem;
    left: 1.216rem;
    position: absolute;
    top: 1.248rem;
    width: 17.76rem;
    .page1-group.active {
      .page1-img {
        animation: fadeIn 1000ms 0ms both;
        transform: scale3d(1.5, 1.5, 1.5);
      }
    }
    .page1-group:nth-child(1) {
      animation: fadeIn 1000ms 1400ms both;
      height: 1.536rem;
      left: 11.584rem;
      position: absolute;
      top: 15.552rem;
      width: 4.48rem;
      .page1-img {
        height: 1.536rem;
        left: 0;
        position: absolute;
        top: 0;
        width: 4.48rem;
      }
    }
    .page1-group:nth-child(2) {
      animation: fadeIn 1000ms 900ms both;
      height: 1.536rem;
      left: 0;
      position: absolute;
      top: 13.056rem;
      width: 4.448rem;
      .page1-img {
        height: 1.536rem;
        left: 0;
        position: absolute;
        top: 0;
        width: 4.448rem;
      }
    }
    .page1-group:nth-child(3) {
      animation: fadeIn 1000ms 1600ms both;
      height: 1.536rem;
      left: 4.576rem;
      position: absolute;
      top: 9.376rem;
      width: 4.448rem;
      .page1-img {
        height: 1.536rem;
        left: 0;
        position: absolute;
        top: 0;
        width: 4.448rem;
      }
    }
    .page1-group:nth-child(4) {
      animation: fadeIn 1000ms 1100ms both;
      height: 1.536rem;
      left: 11.488rem;
      position: absolute;
      top: 10.496rem;
      width: 4.48rem;
      .page1-img {
        height: 1.536rem;
        left: 0;
        position: absolute;
        top: 0;
        width: 4.48rem;
      }
    }
    .page1-group:nth-child(5) {
      animation: fadeIn 1000ms 1000ms both;
      height: 1.536rem;
      left: 0.16rem;
      position: absolute;
      top: 2.656rem;
      width: 4.48rem;
      .page1-img {
        height: 1.536rem;
        left: 0;
        position: absolute;
        top: 0;
        width: 4.48rem;
      }
    }
    .page1-group:nth-child(6) {
      animation: fadeIn 1000ms 1300ms both;
      height: 1.536rem;
      left: 13.28rem;
      position: absolute;
      top: 2.656rem;
      width: 4.48rem;
      .page1-img {
        height: 1.536rem;
        left: 0;
        position: absolute;
        top: 0;
        width: 4.48rem;
      }
    }
    .page1-group:nth-child(7) {
      animation: fadeIn 1000ms 1700ms both;
      height: 1.536rem;
      left: 10.912rem;
      position: absolute;
      top: 0;
      width: 4.48rem;
      .page1-img {
        height: 1.536rem;
        left: 0;
        position: absolute;
        top: 0;
        width: 4.48rem;
      }
    }
  }
  .page1-click-voice {
    animation: fadeIn 1000ms 1900ms both;
    height: 1.536rem;
    left: 3.296rem;
    position: absolute;
    top: 20.704rem;
    width: 11.68rem;
  }
  .page1-click-handle {
    animation: fadeIn 1000ms 1900ms both;
    height: 1.088rem;
    left: 4.096rem;
    position: absolute;
    top: 20.832rem;
    width: 0.672rem;
    img {
      -webkit-animation: twinkling 0.6s infinite ease-in-out;
      animation: twinkling 0.6s infinite ease-in-out;
    }
  }
  .page1-img-content:nth-child(2) {
    animation: fadeInUp 1000ms 2200ms both;
    bottom: 1.528rem;
    height: 2.912rem;
    left: 4.032rem;
    position: absolute;
    width: 16.896rem;
  }
  .page1-img-content:nth-child(3) {
    animation: fadeInRight 1000ms 100ms both;
    height: 4.8rem;
    left: 12rem;
    position: absolute;
    top: 2.528rem;
    width: 5.088rem;
  }
  .page1-img-content:nth-child(4) {
    animation: fadeInLeft 1000ms 100ms both;
    height: 4.8rem;
    left: 6.912rem;
    position: absolute;
    top: 2.528rem;
    width: 5.056rem;
  }
}
</style>

不同的代码实现不同的功能,挺有意思的

上一篇:大疆无人机安卓Mobile Sdk开发(一)简单介绍


下一篇:前端固定table表头方法之纯css实现