@zebra-ui/swiper
Version:
专为多端设计的高性能swiper轮播组件库,支持多种复杂的 3D swiper轮播效果。
48 lines (40 loc) • 1.21 kB
text/typescript
import type { GetBreakpoint } from '../../../types/components/core/breakpoints/get-breakpoint'
const getBreakpoint: GetBreakpoint = (
breakpoints,
base = 'window',
containerEl
) => {
if (!breakpoints || (base === 'container' && !containerEl)) return undefined
let breakpoint: string | false = false
const currentHeight =
base === 'window' ? window.innerHeight : containerEl!.clientHeight
const points = Object.keys(breakpoints).map((point) => {
if (typeof point === 'string' && point.indexOf('@') === 0) {
const minRatio = parseFloat(point.substr(1))
const value = currentHeight * minRatio
return {
value,
point
}
}
return {
value: point,
point
}
})
points.sort(
(a, b) => parseInt(String(a.value), 10) - parseInt(String(b.value), 10)
)
for (let i = 0; i < points.length; i += 1) {
const { point, value } = points[i]
if (base === 'window') {
if (window.matchMedia(`(min-width: ${value}px)`).matches) {
breakpoint = point
}
} else if (Number(value) <= containerEl!.clientWidth) {
breakpoint = point
}
}
return breakpoint || 'max'
}
export default getBreakpoint