Compare commits

..

No commits in common. "9686f58e97a319d1597f86ab47ce72d015ee9d8a" and "ea43f6261a7addb03e6ff80e3eba450661a02816" have entirely different histories.

1 changed files with 17 additions and 40 deletions

View File

@ -30,12 +30,12 @@ let hlsInstance = null
const videoWrapper = ref(null)
const savedScale = parseFloat(localStorage.getItem('videoScale') || '1')
const scale = ref(savedScale)
const scale = ref(1)
const scrollLeft = ref(0)
const scrollTop = ref(0)
const minScale = 1
const maxScale = 3
const scaleStep = 0.2
const showScrollbar = computed(() => scale.value > 1)
@ -90,39 +90,29 @@ const scrollbarYStyle = computed(() => {
})
const zoomIn = () => {
scale.value += scaleStep
localStorage.setItem('videoScale', scale.value.toString())
centerVideo()
if (scale.value < maxScale) {
scale.value = Math.min(maxScale, scale.value + scaleStep)
updateScrollBounds()
}
}
const zoomOut = () => {
if (scale.value > minScale) {
scale.value = Math.max(minScale, scale.value - scaleStep)
localStorage.setItem('videoScale', scale.value.toString())
centerVideo()
updateScrollBounds()
}
}
const centerVideo = () => {
const updateScrollBounds = () => {
if (!videoWrapper.value) return
const wrapper = videoWrapper.value
// clientWidth/clientHeight padding
// 使 clientWidth/clientHeight
const contentWidth = wrapper.clientWidth
const contentHeight = wrapper.clientHeight
if (scale.value <= 1) {
scrollLeft.value = 0
scrollTop.value = 0
return
}
const scaledWidth = contentWidth * scale.value
const scaledHeight = contentHeight * scale.value
scrollLeft.value = (scaledWidth - contentWidth) / 2
scrollTop.value = (scaledHeight - contentHeight) / 2
const wrapperWidth = videoWrapper.value.clientWidth
const wrapperHeight = videoWrapper.value.clientHeight
const maxScrollLeft = Math.max(0, wrapperWidth * (scale.value - 1))
const maxScrollTop = Math.max(0, wrapperHeight * (scale.value - 1))
scrollLeft.value = Math.min(scrollLeft.value, maxScrollLeft)
scrollTop.value = Math.min(scrollTop.value, maxScrollTop)
}
let isDraggingX = false
@ -256,16 +246,6 @@ const initVideo = async () => {
onMounted(() => {
initVideo()
// DOM
nextTick(() => {
centerVideo()
setTimeout(() => {
centerVideo()
}, 100)
setTimeout(() => {
centerVideo()
}, 300)
})
})
onBeforeUnmount(() => {
@ -311,14 +291,11 @@ onBeforeUnmount(() => {
width: 100%;
height: 100%;
transition: width 0.1s ease, height 0.1s ease;
display: flex;
align-items: center;
justify-content: center;
.video-ats {
width: 100%;
height: 100%;
object-fit: contain;
object-fit: fill;
display: block;
}
}