parent
8277a99aae
commit
a6b76ef7f3
@ -0,0 +1,71 @@
|
||||
<template>
|
||||
<div class="container" :style="{height: containerHeight}" @scroll="scroll_event">
|
||||
<div class="list" :style="{top: listTop}">
|
||||
<slot :show_list="getShowList" :show_height="one_height"></slot>
|
||||
<div :style="{height: barHeight}"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</template>
|
||||
|
||||
|
||||
<script>
|
||||
export default{
|
||||
data(){
|
||||
return{
|
||||
start : 0,
|
||||
end : this.shownum,
|
||||
}
|
||||
},
|
||||
props:{
|
||||
shownum: Number,
|
||||
items: Array,
|
||||
one_height: Number,
|
||||
},
|
||||
computed:{
|
||||
containerHeight(){
|
||||
return this.shownum*this.one_height + 'px'
|
||||
},
|
||||
getShowList(){
|
||||
console.log(this.items.slice(this.start,this.end))
|
||||
return this.items.slice(this.start,this.end)
|
||||
},
|
||||
barHeight(){
|
||||
return this.one_height * (this.items.length-this.start-this.shownum+1) + 'px'
|
||||
},
|
||||
listTop(){
|
||||
console.log(this.items,this.shownum,this.one_height)
|
||||
return this.one_height * this.start + 'px'
|
||||
}
|
||||
},
|
||||
methods:{
|
||||
scroll_event(e){
|
||||
const top = e.target.scrollTop
|
||||
this.start = Math.floor(top / this.one_height)
|
||||
this.end = this.start + this.shownum
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
</script>
|
||||
<style scoped>
|
||||
.container{
|
||||
overflow-y: scroll;
|
||||
align-items: center;
|
||||
background-color: transparent;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
scrollbar-color:#F3ABB6 #FFFF;
|
||||
/* text-align: center; */
|
||||
|
||||
/* height: 100px; */
|
||||
}
|
||||
.list{
|
||||
position: relative;
|
||||
top: 0;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
</style>
|
Loading…
Reference in new issue