组件开发

<template>
<div class="swiperpa">
<div class="timeline">
<div class="events-wrapper">
<div class="line" ref='linewidth'>
</div>
<ul>
<li v-for="(point,index) in countpoint" ref='dot' v-on:mouseover="addEffect(point,index)" @click="goTo(index)" :class="{on:index === nowIndex}"></li>
<div class='pulley'></div>
</ul>
</div>
<ul class="timeline-navigation">
<li class="prev" @click="goToPrev()"> </li>
<li class="next" @click="goToNext()" ></li>
</ul>
<div class="play" ref = "play" @click="play()"></div>
<div class="shut" ref = "shut" @click="shut()"></div>
</div>
</div>
</template>
<script>
export default {
props: {
inv: {
type: Number,
default: 1000,
},
countpoint:{
type:Number,
default:50,
},
},
data() {
return {
nowIndex: 0,
curPage:1,
pageNum:10,
// points: [
// new BMap.Point(117.227819, 23.814327),
// new BMap.Point(117.171452, 23.800036),
// new BMap.Point(117.132368, 23.791609),
// new BMap.Point(117.076919, 23.764658),
// new BMap.Point(117.024827, 23.754510),
// new BMap.Point(116.981047, 23.739533),
// new BMap.Point(116.939091, 23.717617),
// new BMap.Point(116.900199, 23.699399),
// new BMap.Point(116.885031, 23.689196),
// new BMap.Point(116.874584, 23.679668),
// new BMap.Point(116.811841, 23.626940),
// new BMap.Point(116.759632, 23.604713),
// new BMap.Point(116.725061, 23.587160),
// new BMap.Point(116.651402, 23.566650),
// new BMap.Point(116.595323, 23.545934),
// new BMap.Point(116.565463, 23.533553),
// new BMap.Point(116.552337, 23.519046),
// new BMap.Point(116.544596, 23.508704),
// new BMap.Point(116.537630, 23.464337),
// new BMap.Point(116.528264, 23.443634),
// new BMap.Point(116.518571, 23.425543),
// new BMap.Point(116.502256, 23.414608),
// new BMap.Point(116.429954, 23.388459),
// new BMap.Point(116.388039, 23.368854),
// new BMap.Point(116.352537, 23.347284),
// new BMap.Point(116.281605, 23.327247),
// new BMap.Point(116.227800, 23.293717),
// new BMap.Point(116.214108, 23.280499),
// ]
}
},
created() {

},
computed: {
nextIndex() {
if (this.nowIndex === this.countpoint - 1) {
return 0
} else {
return this.nowIndex + 1
}
}
},
methods: {
drawLine() {
this.$refs.linewidth.style.width = (this.countpoint - 1) * 0.3 + "rem"
},
permutation() {
// console.log(this.$refs.dot, 'this.refs.dot')
var j = -1; //从初始点开始
this.$refs.dot.forEach((ele, ind) => {
j++
ele.style.left = j * 0.3 + "rem" //分隔排列

  })
},
addEffect(evnet, point, ind) {
  // console.log(event.target, point, 'event')
},
goTo(index) {
  this.nowIndex = index
  this.$emit("onchange", index)
  // console.log(index,'index')
  // this.$emit("change", this.index)
},
goToPrev() {
  //判断切换
  if( this.$refs.play.style.display = "none"){
     this.$refs.shut.style.display = "none"
     this.$refs.play.style.display = "block"
  }
  clearInterval(this.invId)
  this.nowIndex = 0;
  if(this.curPage >1){
      this.curPage -=1
      // console.log(this.curPage,"this.curPage")
      this.$emit("changepage", this.curPage)
  }


  // this.$refs.line.style = "transition:all .5s;transform:translateX(-900px)"
  //发送请求获取新的包
  //告诉父组件一个事件,事件包括(发送请求 请求页面条数,将请求的放数组中去,画线要放到计算属性里面,points改变而改变)
},
goToNext() {
  // console.log(this.curPage ,"goNext")
  if( this.$refs.play.style.display = "none"){
     this.$refs.shut.style.display = "none"
     this.$refs.play.style.display = "block"
  }
  clearInterval(this.invId)
  this.nowIndex = 0;
  if(this.curPage >= 1 && this.curPage < this.pageNum){
      this.curPage += 1
      // console.log(this.curPage,'this.curpage')
      this.$emit("changepage", this.curPage)
  }
  // this.$refs.line.style = "transition:all .5s;transform:translateX(-900px)"
},
play() {
  // console.log("play")
  // console.log('this.$refs.play')
  this.$refs.play.style.display = "none"
  this.runInv()

  this.$refs.shut.style.display = "block"
},
shut() {
  this.clearInv()
  this.$refs.shut.style.display = "none"
  this.$refs.play.style.display = "block"
},
runInv() {
  let    timeSpeed = this.inv
  this.invId = setInterval(() => {
    this.goTo(this.nextIndex)

  }, timeSpeed )
},
clearInv() {
  clearInterval(this.invId)
},

},
// watch: {
// curIndex() {
// this.$emit("onchange", this.curIndex)
// }
// },
mounted() {
this.$nextTick(() => {
this.permutation();
this.drawLine()
})
}
}

</script>
<style lang="scss" scoped>
@import './src/assets/css/global.scss';
.swiperpa {
// @media screen and (max-device-width: 3000px) and(min-device-width:1920px){
// .timeline {
// width: 18.87rem;//边框也算
// }
// }
@media screen and (max-device-width: 1920px) and(min-device-width:0px){
.timeline {
width: 15.87rem;//边框也算
}
}

.timeline {
position: relative;
height: 50px;
margin: 0 auto;
// border: 1px solid red;

.events-wrapper {
  position: relative;
  height: 100%; // margin: 0 auto;
   // overflow: hidden;
  font-size: 0;
  // border: 1px solid blue;
  margin: 0 0.48rem;
  .line {
    position: absolute;
    z-index: 1;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    height: 0.02rem;
    background: #d9d9d9;
    transition: transform 0.4s;
    width: 100%;
  }
  li {
    position: absolute;
    display: inline-block;
    top: 50%;
    transform: translateY(-50%);
    z-index: 20px;
    height: 12px;
    width: 12px;
    border-radius: 8px;
    border: 0.02rem solid #dfdfdf;
    background-color: #fff;
    z-index: 100; // left:100px;
    cursor: pointer;
  }
  .on{
     border: 2px solid red;
  }
  .pulley {
    position: absolute;
    top: 20px;
    height: 30px;
    width: 30px; // background-color:red;
  }
}
.timeline-navigation {
  .prev {
    position: absolute;
    left:0.1rem;
    top: 50%;
    transform: translateY(-50%);
    width: 20px;
    height: 20px;
    border: 2px solid red;
    border-radius: 50%;
    background: #fff;
    cursor: pointer;
  }
  .next {
    position: absolute;
    right: 0.1rem;
    top: 50%;
    transform: translateY(-50%);
    width: 20px;
    height: 20px;
    border: 2px solid red;
    border-radius: 50%;
    background: #fff;
    cursor: pointer;
  }
}
.play {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  left: 0;
  margin-left: -40px;
  height: 30px;
  width: 30px;
  background-color: red;
  cursor: pointer;
}
.shut {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  left: 0;
  margin-left: -40px;
  height: 30px;
  width: 30px;
  background-color: blue;
  cursor: pointer;
  display:none;
}

}
}

</style>

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 196,302评论 5 462
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 82,563评论 2 373
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 143,433评论 0 325
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 52,628评论 1 267
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 61,467评论 5 358
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 46,354评论 1 273
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 36,777评论 3 387
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 35,419评论 0 255
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 39,725评论 1 294
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 34,768评论 2 314
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 36,543评论 1 326
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 32,387评论 3 315
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 37,794评论 3 300
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,032评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,305评论 1 252
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 41,741评论 2 342
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 40,946评论 2 336

推荐阅读更多精彩内容

  • 1. 新建组件: Vue.component 方法用于注册全局组件,new Vue({ components: {...
    rayman_v阅读 690评论 0 3
  • 使用规范 使用:prop 传递数据类型为数字 或 boolean时,必须带 :,比如: 开发规范 开发之前 尽量使...
    August_____阅读 2,234评论 6 5
  • 课程前言: 慕课网 -- DatePicker组件开发 课程准备: HTML、CSS、JavaScript基础、浏...
    一树青枫阅读 2,590评论 0 1
  • 七律 堵车 诗/老财神(霍胜泽) 玉带恢宏四海连,笛鸣滚滚破云烟。 长蛇逶迤无边际,大雁徘徊一线天。 万户亲朋...
    老财神阅读 1,143评论 0 5
  • 小王子在沙坡遇到了狐狸聪明的狐狸请求小王子需要他他说宣扬就是建立感情在驯养之前你对我来说不过是一个男孩子,跟成千上...
    文晓娅阅读 156评论 0 0