effect-init.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. export default function effectInit(params) {
  2. const {
  3. effect,
  4. swiper,
  5. on,
  6. setTranslate,
  7. setTransition,
  8. overwriteParams,
  9. perspective
  10. } = params;
  11. on('beforeInit', () => {
  12. if (swiper.params.effect !== effect) return;
  13. swiper.classNames.push(`${swiper.params.containerModifierClass}${effect}`);
  14. if (perspective && perspective()) {
  15. swiper.classNames.push(`${swiper.params.containerModifierClass}3d`);
  16. }
  17. const overwriteParamsResult = overwriteParams ? overwriteParams() : {};
  18. Object.assign(swiper.params, overwriteParamsResult);
  19. Object.assign(swiper.originalParams, overwriteParamsResult);
  20. });
  21. on('setTranslate', () => {
  22. if (swiper.params.effect !== effect) return;
  23. setTranslate();
  24. });
  25. on('setTransition', (_s, duration) => {
  26. if (swiper.params.effect !== effect) return;
  27. setTransition(duration);
  28. });
  29. let requireUpdateOnVirtual;
  30. on('virtualUpdate', () => {
  31. if (!swiper.slides.length) {
  32. requireUpdateOnVirtual = true;
  33. }
  34. requestAnimationFrame(() => {
  35. if (requireUpdateOnVirtual && swiper.slides.length) {
  36. setTranslate();
  37. requireUpdateOnVirtual = false;
  38. }
  39. });
  40. });
  41. }