国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

vue-music 使用better-scroll遇到輪播圖不能自動輪播問題

2024-05-06 15:27:35
字體:
來源:轉載
供稿:網(wǎng)友

根據(jù)vue-music視頻中slider組建的使用,當安裝新版本的better-scroll,輪播組件,不能正常輪播

這是因為,better-scroll發(fā)布新版本之后,參數(shù)設置發(fā)生改變

這是舊版本: 組件為slider

<template> <div class="slider" ref="slider">  <div class="slider-group" ref="sliderGroup">   <slot>   </slot>  </div>  <div class="dots">   <span class="dot" :class="{active: currentPageIndex === index }" v-for="(item, index) in dots" :key="item.id"></span>  </div> </div></template><script type="text/ecmascript-6">import { addClass } from "common/js/dom";import BScroll from "better-scroll";export default { name: "slider", props: {  loop: {   type: Boolean,   default: true  },  autoPlay: {   type: Boolean,   default: true  },  interval: {   type: Number,   default: 4000  } }, data() {  return {   dots: [],   currentPageIndex: 0  }; }, mounted() {  setTimeout(() => {   this._setSliderWidth();   this._initDots();   this._initSlider();   if (this.autoPlay) {    this._play();   }  }, 20);  window.addEventListener("resize", () => {   if (!this.slider) {    return;   }   this._setSliderWidth(true);   this.slider.refresh();  }); }, activated() {  if (this.autoPlay) {   this._play();  } }, deactivated() {  clearTimeout(this.timer); }, beforeDestroy() {  clearTimeout(this.timer); }, methods: {  _setSliderWidth(isResize) {   this.children = this.$refs.sliderGroup.children;   let width = 0;   let sliderWidth = this.$refs.slider.clientWidth;   for (let i = 0; i < this.children.length; i++) {    let child = this.children[i];    addClass(child, "slider-item");    child.style.width = sliderWidth + "px";    width += sliderWidth;   }   if (this.loop && !isResize) {    width += 2 * sliderWidth;   }   this.$refs.sliderGroup.style.width = width + "px";  },  _initSlider() {   // better-scroll 對外暴露了一個 BScroll 的類   // Vue.js 提供了我們一個獲取 DOM 對象的接口—— vm.$refs   this.slider = new BScroll(this.$refs.slider, {    scrollX: true,    scrollY: false,    momentum: false,    snap: true,    snapLoop: this.loop,    snapThreshold: 0.3,    snapSpeed: 400   });   // 是否派發(fā)滾動到底部事件,用于上拉加載  // 切換到下一張的時候派發(fā)的事件   this.slider.on("scrollEnd", () => {    let pageIndex = this.slider.getCurrentPage().pageX;    if (this.loop) {     pageIndex -= 1;    }    this.currentPageIndex = pageIndex;    if (this.autoPlay) {     this._play();    }   });   // 是否派發(fā)列表滾動開始的事件   this.slider.on("beforeScrollStart", () => {    if (this.autoPlay) {     clearTimeout(this.timer);    }   });  },  _initDots() {   this.dots = new Array(this.children.length);  },  _play() {   let pageIndex = this.currentPageIndex + 1;   if (this.loop) {    pageIndex += 1;   }   this.timer = setTimeout(() => {    this.slider.goToPage(pageIndex, 0, 400);   }, this.interval);  } }};</script><style scoped lang="stylus" rel="stylesheet/stylus">@import '~common/stylus/variable';.slider { min-height: 1px; .slider-group {  position: relative;  overflow: hidden;  white-space: nowrap;  .slider-item {   float: left;   box-sizing: border-box;   overflow: hidden;   text-align: center;   a {    display: block;    width: 100%;    overflow: hidden;    text-decoration: none;   }   img {    display: block;    width: 100%;   }  } } .dots {  position: absolute;  right: 0;  left: 0;  bottom: 12px;  text-align: center;  font-size: 0;  .dot {   display: inline-block;   margin: 0 4px;   width: 8px;   height: 8px;   border-radius: 50%;   background: $color-text-l;   &.active {    width: 20px;    border-radius: 5px;    background: $color-text-ll;   }  } }}</style>            
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表

圖片精選

主站蜘蛛池模板: 钟祥市| 芦溪县| 潢川县| 龙胜| 南开区| 万州区| 通渭县| 津市市| 汉阴县| 浮梁县| 陵水| 永顺县| 呼玛县| 天全县| 介休市| 富锦市| 安阳县| 婺源县| 吉林省| 阳城县| 汾西县| 屏东县| 剑阁县| 乐平市| 大城县| 壶关县| 英山县| 来安县| 武穴市| 日土县| 勃利县| 上蔡县| 巧家县| 房产| 乌兰浩特市| 精河县| 思茅市| 犍为县| 女性| 东阳市| 开江县|