index.js 990 B

12345678910111213141516171819202122232425262728293031323334
  1. //DOM操作、Ajax
  2. import 'http://code.jquery.com/jquery-2.1.1.min.js'
  3. //轮播图
  4. import Swiper from 'https://unpkg.com/swiper@8/swiper-bundle.esm.browser.min.js'
  5. window.Swiper = Swiper
  6. /**
  7. * 执行动画
  8. * @param ele 元素的选择器
  9. * @description 如果元素滚动至距离底部150px以上,添加css动效
  10. */
  11. window.showAnimate = function (ele, className) {
  12. //监听页面滚动
  13. window.onscroll = function (event) {
  14. if ($(ele).offset().top <= $(window).height() + $(window).scrollTop() - 150) {
  15. $(ele).addClass(className)
  16. }
  17. }
  18. }
  19. let swiper = new Swiper('#swiper1', {
  20. pagination: {
  21. el: '.swiper-pagination',
  22. },
  23. loop: true, //循环
  24. observer: true, //修改swiper自己或子元素时,自动初始化swiper
  25. observeParents: true, //修改swiper的父元素时,自动初始化swiper
  26. speed: 500,
  27. autoplay: {
  28. disableOnInteraction: false, //触碰后自动轮播也不会停止
  29. delay: 3000,
  30. },
  31. })