自定义vue组件小集合

来源:互联网 发布:sns 网络 营销 案例 编辑:程序博客网 时间:2024/05/16 08:01

横向自动滚动tab

<template><div class="cover_box" id="cover_box"><ul class="left_move" id="left_move"><li v-for="(item,index) in move_data" @click="select(item)" :class="{active:item===select_obj||(index===0&&select_obj===null)}">{{item.title}}</li></ul></div></template><style scoped>.cover_box{width: 16.0rem;height: 2.0rem;overflow: scroll;background-color: white;}.cover_box::-webkit-scrollbar{width: 0;height: 0;}.left_move{width: auto; height: 2.0rem;padding-top: 0.45rem;left: 0.0rem; white-space: nowrap;position: absolute;}.left_move li{width: 3.35rem;height: 1.2rem;margin-left: 0.45rem;font-size: 0.6rem; line-height: 1.2rem;border-radius: 0.8rem; border:0.05rem solid #999999; display: inline-block; float: none;}.left_move .active{border-color: red;color: red;}</style><script type="text/babel">export default{data(){return{left_move:null,select_obj:null,left_move_child_set:null,move_data:[{title:'1项填充'},{title:'2项填充'},{title:'3项填充'},{title:'4项填充'},{title:'5项填充'},{title:'6项填充'},{title:'7项填充'},{title:'8项填充'},{title:'9项填充'},{title:'10项填充'},{title:'11项填充'}]}},mounted:function(){this.left_move = $('.left_move')this.left_move_child_set = this.left_move.children('li')for(var a = 0;a<this.left_move_child_set.length;a++){this.left_move_child_set.eq(a).click(function(){if(this.offsetLeft>document.body.clientWidth/2){$('.cover_box').animate({scrollLeft:(this.offsetLeft-document.body.clientWidth/2)+this.offsetWidth/2+'px'}, 500); }else{$('.cover_box').animate({scrollLeft:'0px'}, 500); }})}},methods:{select:function(item){this.select_obj = item}}}</script>


原创粉丝点击