老师,唱片旋转我有疑问,咋个能让它切下一首歌的时候恢复成原始角度呢?
来源:5-10 播放器 cd 唱片旋转相关逻辑开发
viTaemin_nanali
2021-07-14
点击切换上一首或者下一首时,唱片的角度也是叠加的,如何把它改为切下一首还原成从正北开始超右边旋转?
3回答
-
viTaemin_nanali
提问者
2021-08-11
import { ref, computed, watch } from 'vue'
import { useStore } from 'vuex'
export default function useCD () {
const cdWrapper = ref(null)
const cdRef = ref(null)
const reset = ref(false)
const store = useStore()
const playing = computed(() => store.state.playing)
const currentSong = computed(() => store.getters.currentSong)
const cdCls = computed(() => {
return (!reset.value && playing.value) ? 'playing' : ''
})
watch(playing, newPlaying => {
if (!newPlaying) {
synchronizeAnimationAngle(cdWrapper.value, cdRef.value)
}
})
watch(currentSong, () => {
reset.value = true
cdWrapper.value.style.transform = 'none'
setTimeout(() => {
reset.value = false
}, 200)
})
function synchronizeAnimationAngle (wrapper, inner) {
const wrapperTrans = getComputedStyle(wrapper).transform
const innerTrans = getComputedStyle(inner).transform
wrapper.style.transform = wrapperTrans === 'none' ? innerTrans : innerTrans.concat(' ', wrapperTrans)
}
return {
cdWrapper,
cdRef,
cdCls
}
}
00 -
AshinLX
2021-08-02
请问你这个问题解决了吗,我也用的你那种监听currentIndex的方式去清空,但是没生效
062021-12-23 -
ustbhuangyi
2021-07-14
清空 transform 的值就可以了吧
052021-07-15
相似问题