這篇文章將為大家詳細講解有關(guān)vue如何封裝swiper代碼,小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。
data(){ return{ list:[], swiperOption:"", xiding : "", // 輪播高度 SwiperHeight:'' } }, mounted(){ this.onload() // 獲取輪播圖圖片的高度 setTimeout(()=> { // 通過ref獲取輪播dom,獲取輪播的高度 console.log(this.$refs.mySwiper.$el.offsetHeight) this.SwiperHeight = this.$refs.mySwiper.$el.offsetHeight },2000) // 監(jiān)聽滑動事件 window.onscroll = this.handleScroll }, destroyed(){ window.onscroll = null; //清除滑動事件綁定 }, methods:{ handleScroll(){ // 獲取屏幕滑動的高度 console.log(document.documentElement.scrollTop) // 滑動高度 > 輪播dom高度 吸頂 if(document.documentElement.scrollTop > this.SwiperHeight){ // 吸頂 this.xiding = true }else{ // 取消吸 this.xiding = false } },
關(guān)于“vue如何封裝swiper代碼”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,使各位可以學到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。