imgLoading.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <template>
  2. <div class="section-loading" v-if="progress != 100">
  3. <div class="section1-wwbox">
  4. <img src="/img/section1/section1-ww.webp" alt="" class="fadeIn">
  5. <div class="title2 fadeIn"></div>
  6. <div>
  7. <div class="icon">
  8. <img src="./img/webp/wsicon.webp" alt="">
  9. </div>
  10. <p id="progress-bar"><span>{{ progress }}</span>%</p>
  11. </div>
  12. </div>
  13. </div>
  14. </template>
  15. <script setup>
  16. import { onMounted, ref, watchEffect } from "vue";
  17. import { emitter } from "../emitter.js";
  18. import imgList from '../utils/loadImg'
  19. defineOptions({
  20. name: "img-loading",
  21. });
  22. onMounted(()=>{
  23. loadImages(imgList)
  24. })
  25. const props = defineProps({
  26. fullpage: Object,
  27. });
  28. const progress = ref(0);
  29. const framePro = ref(0)
  30. const imgPro = ref(0)
  31. watchEffect(() => {
  32. if (progress.proxy.$refs.fullpage) {
  33. fullpage.value = instance.proxy.$refs.fullpage;
  34. }
  35. });
  36. emitter.on("updatePress", (val) => {
  37. framePro.value = val * 0.7
  38. progress.value = Math.round(framePro.value + imgPro.value)
  39. });
  40. // 总任务
  41. function loadImages(list){
  42. const pageSize = 1
  43. let pageNum = 0 ,totalNum = list.length;
  44. return new Promise((reslove,reject)=>{
  45. function run(){
  46. Promise.all(genetateTasks(list,pageSize,pageNum)).then(()=>{
  47. pageNum++
  48. const hasLength = pageSize * pageNum
  49. imgPro.value = Math.round((hasLength/(list.length + 1))*30)
  50. progress.value = Math.round(framePro.value + imgPro.value)
  51. if(totalNum > hasLength){
  52. run()
  53. }else {
  54. reslove(true)
  55. } })
  56. }
  57. run()
  58. }) }
  59. // 子任务
  60. function genetateTasks(list,pageSize,pageNum){
  61. const promiseArr = []
  62. const start = pageNum * pageSize
  63. const end = (pageNum + 1) * pageSize - 1
  64. // progress.value =
  65. for(let i = start;i<end;i++){
  66. const p = new Promise((reslove,reject)=>{
  67. const img = new Image()
  68. img.src = list[i]
  69. img.onload = img.onerror = reslove
  70. })
  71. promiseArr.push(p)
  72. }
  73. return promiseArr
  74. }
  75. // emitter.on("closePreloadinng");
  76. // emitter.emit("preBaseLoadingdone");
  77. </script>
  78. <style lang="scss" scoped>
  79. @import "/src/assets/style/index.css";
  80. .icon {
  81. width: 25px;
  82. height: 25px;
  83. img {
  84. width: 100%;
  85. }
  86. }
  87. .text{
  88. text-align: center;
  89. }
  90. .scroll-icon {
  91. opacity: 1;
  92. z-index: 10;
  93. position: absolute;
  94. bottom: 1em;
  95. left: 50%;
  96. margin-left: -0.6em;
  97. display: -webkit-box;
  98. display: -ms-flexbox;
  99. display: flex;
  100. justify-content: center;
  101. align-items: center;
  102. height: 2em;
  103. width: 1.2em;
  104. font-size: 22px;
  105. color: rgba(255, 255, 255, 0.5);
  106. border-radius: 2em;
  107. border: solid 2px;
  108. transition: 0.4s;
  109. &::before {
  110. content: "";
  111. display: inline-block;
  112. width: 5px;
  113. height: 5px;
  114. background-color: #fff;
  115. border-radius: 50%;
  116. animation: scroll-icon 2.2s infinite cubic-bezier(0.75, 0.05, 0.36, 1);
  117. }
  118. }
  119. @keyframes scroll-icon {
  120. 0% {
  121. transform: translateY(-12px);
  122. opacity: 0;
  123. }
  124. 30%,
  125. 70% {
  126. opacity: 1;
  127. }
  128. 100% {
  129. transform: translateY(12px);
  130. opacity: 0;
  131. }
  132. }
  133. </style>