App.vue 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <script setup>
  2. import { computed, onMounted, ref } from 'vue';
  3. import Loader from '@/components/Loader.vue';
  4. import ScrollDown from '@/components/ScrollDown.vue';
  5. import Image from '@/components/Image.vue';
  6. import { preload } from '@/utils/preload';
  7. import scroll from '@/utils/scroll'
  8. const fixedLogo = './fixed-logo.png';
  9. const loading = ref(true);
  10. const percent = ref(0);
  11. const resources = ref([]);
  12. const fixedLogoHidden = ref(false);
  13. const unScroll = ref()
  14. const updateCallback = (num) => {
  15. percent.value = Math.round(num * 100);
  16. }
  17. const onClick = () => {
  18. // logo2URL 来自于 public/config.js
  19. window.location.href = logo2URL;
  20. }
  21. onMounted(() => {
  22. const { onStart, onEnd } = scroll(window.document);
  23. onStart(() => {
  24. fixedLogoHidden.value = true;
  25. })
  26. onEnd(() => {
  27. fixedLogoHidden.value = false;
  28. })
  29. preload(updateCallback).then((res) => {
  30. loading.value = false;
  31. resources.value = res.filter(x => !x.hidden);
  32. })
  33. });
  34. </script>
  35. <template>
  36. <Loader :loading="loading" :percent="percent" />
  37. <ScrollDown />
  38. <Image v-for="(res, index) in resources" :key="res.image" :resource="res" :index="index"></Image>
  39. <img :src="fixedLogo" alt="" class="fixed-log" :class="{ 'hidden': fixedLogoHidden }" @click="onClick">
  40. </template>
  41. <style lang="less" scoped>
  42. .fixed-log {
  43. position: fixed;
  44. right: 20px;
  45. bottom: 100px;
  46. z-index: 50;
  47. width: 48px;
  48. height: 48px;
  49. border: none;
  50. box-shadow: 0 0 2px 2px rgba(0,0,0, .1);
  51. border-radius: 50%;
  52. transition: all 0.6s;
  53. opacity: 1;
  54. will-change: right opacity;
  55. &.hidden {
  56. right: -10px;
  57. opacity: 0;
  58. }
  59. }
  60. </style>