updateSize.js 977 B

123456789101112131415161718192021222324252627282930313233
  1. export default function updateSize() {
  2. const swiper = this;
  3. let width;
  4. let height;
  5. const $el = swiper.$el;
  6. if (typeof swiper.params.width !== 'undefined' && swiper.params.width !== null) {
  7. width = swiper.params.width;
  8. } else {
  9. width = $el[0].clientWidth;
  10. }
  11. if (typeof swiper.params.height !== 'undefined' && swiper.params.height !== null) {
  12. height = swiper.params.height;
  13. } else {
  14. height = $el[0].clientHeight;
  15. }
  16. if (width === 0 && swiper.isHorizontal() || height === 0 && swiper.isVertical()) {
  17. return;
  18. } // Subtract paddings
  19. width = width - parseInt($el.css('padding-left') || 0, 10) - parseInt($el.css('padding-right') || 0, 10);
  20. height = height - parseInt($el.css('padding-top') || 0, 10) - parseInt($el.css('padding-bottom') || 0, 10);
  21. if (Number.isNaN(width)) width = 0;
  22. if (Number.isNaN(height)) height = 0;
  23. Object.assign(swiper, {
  24. width,
  25. height,
  26. size: swiper.isHorizontal() ? width : height
  27. });
  28. }