main.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. var swiper = new Swiper('.swiper-container', {
  2. direction: 'vertical',
  3. mousewheelControl: true,
  4. nextButton:'.button-next',
  5. onInit: function (swiper) {
  6. swiperAnimate(swiper);
  7. },
  8. onSlideChangeEnd: function (swiper) {
  9. swiperAnimate(swiper);
  10. },
  11. })
  12. var loader = (function () {
  13. var loadingContainer = document.getElementById('loadingCont')
  14. var loadingTxt = document.getElementById('loadingTxt')
  15. var loadingCircle = document.getElementById('loadingCircle')
  16. var loadingCircleP = loadingCircle.getAttribute('stroke-dasharray')
  17. var imgs = document.getElementsByTagName('img')
  18. var srcList = []
  19. var imgList = []
  20. var imgSrc, i
  21. for (i = 0; i < imgs.length; i++) {
  22. imgSrc = imgs[i].getAttribute('pre-src')
  23. if (imgSrc) {
  24. srcList.push(imgSrc)
  25. imgList.push(imgs[i])
  26. }
  27. }
  28. if (srcList.length === 0) {
  29. swiper.container[0].style.opacity = 1
  30. loadingContainer.style.opacity = 0
  31. swiperAnimate(swiper)
  32. }
  33. return new resLoader({
  34. resources: srcList,
  35. onStart: function (total) {
  36. console.log('start:' + total)
  37. },
  38. onProgress: function (current, total) {
  39. console.log(current + '/' + total)
  40. var p = current / total
  41. loadingTxt.textContent = Math.round(p * 100) + '%'
  42. loadingCircle.style.strokeDashoffset = (1 - p) * loadingCircleP
  43. },
  44. onComplete: function (total) {
  45. console.log('加载完毕:' + total + '个资源')
  46. for (i = 0; i < imgList.length; i++) {
  47. imgList[i].setAttribute('src', srcList[i])
  48. }
  49. swiper.container[0].style.opacity = 1
  50. loadingContainer.style.opacity = 0
  51. swiperAnimate(swiper)
  52. }
  53. })
  54. })()
  55. loader.start()