index.html部分如下:
html,body {
padding: 0;
margin: 0;
}
.table-head-fixed {
position: fixed;
top: 0;
left: 0;
width: 100%;
}
table {
width: 100%;
}
th {
background-color: #ccc;
}
td,th {
height: 2rem;
width: 33.3%;
padding: 0.5rem;
box-sizing: border-box;
border-bottom: 1px solid #ccc;
border-right: 1px solid #ccc;
}
ul,li {
margin: 0;
padding: 0;
}
ul li {
list-style: none;
border-bottom: 1px solid #ccc;
padding: 1rem;
}
{{item.name}}
age | name | sex |
---|
{{item.NAME}} | {{item.ACTIVE_TYPE}} | {{item.DATE}} |
{{item.name}}
{{item.name}}
var demo = new Vue({
mixins: [table],
el: "#app",
data: function() {
return {}
},
watch: {},
mounted: function() {
this.scroll()
},
created: function() {},
methods: {
scroll: function() {
var that = this
window.addEventListener('scroll', that.throttle(that, that.fixedTable, 200))
},
//函数节流,在规定时间内才执行一次图片加载函数,解决耗费性能,浏览器卡顿问题。
throttle: function(that, fixedTable, wait) {
var lastTime = new Date().getTime()
return function() {
var curTime = new Date().getTime()
if(curTime - lastTime < wait) return
lastTime = curTime
fixedTable(that)
}
},
//固定table头部
fixedTable: function(that) {
var eleOffsetTop = that.$refs.tableBody.offsetTop - that.$refs.tableHead.clientHeight
var scrollTop = document.body.scrollTop || document.documentElement.scrollTop;
var tableBodyH = that.$refs.tableBody.clientHeight
if(eleOffsetTop <= scrollTop && eleOffsetTop + tableBodyH > scrollTop) {
that.$refs.tableHead.className = "table-head table-head-fixed"
} else {
that.$refs.tableHead.className = "table-head"
}
}
}
})
混入js(table.js)部分如下:
var table = {
data: function() {
return {
ulData: [{
name: 1,
}, {
name: 2,
}, {
name: 3,
}, {
name: 4,
}, {
name: 5,
}, {
name: 6,
}, {
name: 4,
}, {
name: 5,
}, {
name: 6,
}, {
name: 4,
}, {
name: 5,
}, {
name: 6,
}],
tableData: [{
"NAME": "电影",
"TYPE": "兴趣",
"ACTIVE_TYPE": "社交",
"DATE": "2020-02-04",
"BEGIN_DATE": "09:30",
"END_DATE": "11:45",
"HOURS": "2小时15分钟",
"PERSON": 45,
"JOIN_PERSON": 30,
"SPONSOR": "独立区",
"LABEL": "",
"USE_PLACE": "2号楼多工能厅",
"SCOPE": "课程",
"SON_COURSE": "欣赏课",
"CLUB_NAME": "娱乐",
"TEACHER_NAME": "王xx",
"TEACHER_TYPE": "员工",
"DATA_UPDATE": "2020-02-04 13:50"
},
{
"NAME": "电影",
"TYPE": "兴趣",
"ACTIVE_TYPE": "社交",
"DATE": "2020-02-04",
"BEGIN_DATE": "09:30",
"END_DATE": "11:45",
"HOURS": "2小时15分钟",
"PERSON": 45,
"JOIN_PERSON": 30,
"SPONSOR": "独立区",
"LABEL": "",
"USE_PLACE": "2号楼多工能厅",
"SCOPE": "课程",
"SON_COURSE": "欣赏课",
"CLUB_NAME": "娱乐",
"TEACHER_NAME": "王xx",
"TEACHER_TYPE": "员工",
"DATA_UPDATE": "2020-02-04 13:50"
}, {
"NAME": "电影",
"TYPE": "兴趣",
"ACTIVE_TYPE": "社交",
"DATE": "2020-02-04",
"BEGIN_DATE": "09:30",
"END_DATE": "11:45",
"HOURS": "2小时15分钟",
"PERSON": 45,
"JOIN_PERSON": 30,
"SPONSOR": "独立区",
"LABEL": "",
"USE_PLACE": "2号楼多工能厅",
"SCOPE": "课程",
"SON_COURSE": "欣赏课",
"CLUB_NAME": "娱乐",
"TEACHER_NAME": "王xx",
"TEACHER_TYPE": "员工",
"DATA_UPDATE": "2020-02-04 13:50"
}, {
"NAME": "电影",
"TYPE": "兴趣",
"ACTIVE_TYPE": "社交",
"DATE": "2020-02-04",
"BEGIN_DATE": "09:30",
"END_DATE": "11:45",
"HOURS": "2小时15分钟",
"PERSON": 45,
"JOIN_PERSON": 30,
"SPONSOR": "独立区",
"LABEL": "",
"USE_PLACE": "2号楼多工能厅",
"SCOPE": "课程",
"SON_COURSE": "欣赏课",
"CLUB_NAME": "娱乐",
"TEACHER_NAME": "王xx",
"TEACHER_TYPE": "员工",
"DATA_UPDATE": "2020-02-04 13:50"
},
{
"NAME": "电影",
"TYPE": "兴趣",
"ACTIVE_TYPE": "社交",
"DATE": "2020-02-04",
"BEGIN_DATE": "09:30",
"END_DATE": "11:45",
"HOURS": "2小时15分钟",
"PERSON": 45,
"JOIN_PERSON": 30,
"SPONSOR": "独立区",
"LABEL": "",
"USE_PLACE": "2号楼多工能厅",
"SCOPE": "课程",
"SON_COURSE": "欣赏课",
"CLUB_NAME": "娱乐",
"TEACHER_NAME": "王xx",
"TEACHER_TYPE": "员工",
"DATA_UPDATE": "2020-02-04 13:50"
}, {
"NAME": "电影",
"TYPE": "兴趣",
"ACTIVE_TYPE": "社交",
"DATE": "2020-02-04",
"BEGIN_DATE": "09:30",
"END_DATE": "11:45",
"HOURS": "2小时15分钟",
"PERSON": 45,
"JOIN_PERSON": 30,
"SPONSOR": "独立区",
"LABEL": "",
"USE_PLACE": "2号楼多工能厅",
"SCOPE": "课程",
"SON_COURSE": "欣赏课",
"CLUB_NAME": "娱乐",
"TEACHER_NAME": "王xx",
"TEACHER_TYPE": "员工",
"DATA_UPDATE": "2020-02-04 13:50"
}, {
"NAME": "电影",
"TYPE": "兴趣",
"ACTIVE_TYPE": "社交",
"DATE": "2020-02-04",
"BEGIN_DATE": "09:30",
"END_DATE": "11:45",
"HOURS": "2小时15分钟",
"PERSON": 45,
"JOIN_PERSON": 30,
"SPONSOR": "独立区",
"LABEL": "",
"USE_PLACE": "2号楼多工能厅",
"SCOPE": "课程",
"SON_COURSE": "欣赏课",
"CLUB_NAME": "娱乐",
"TEACHER_NAME": "王xx",
"TEACHER_TYPE": "员工",
"DATA_UPDATE": "2020-02-04 13:50"
}, {
"NAME": "电影",
"TYPE": "兴趣",
"ACTIVE_TYPE": "社交",
"DATE": "2020-02-04",
"BEGIN_DATE": "09:30",
"END_DATE": "11:45",
"HOURS": "2小时15分钟",
"PERSON": 45,
"JOIN_PERSON": 30,
"SPONSOR": "独立区",
"LABEL": "",
"USE_PLACE": "2号楼多工能厅",
"SCOPE": "课程",
"SON_COURSE": "欣赏课",
"CLUB_NAME": "娱乐",
"TEACHER_NAME": "王xx",
"TEACHER_TYPE": "员工",
"DATA_UPDATE": "2020-02-04 13:50"
}, {
"NAME": "电影",
"TYPE": "兴趣",
"ACTIVE_TYPE": "社交",
"DATE": "2020-02-04",
"BEGIN_DATE": "09:30",
"END_DATE": "11:45",
"HOURS": "2小时15分钟",
"PERSON": 45,
"JOIN_PERSON": 30,
"SPONSOR": "独立区",
"LABEL": "",
"USE_PLACE": "2号楼多工能厅",
"SCOPE": "课程",
"SON_COURSE": "欣赏课",
"CLUB_NAME": "娱乐",
"TEACHER_NAME": "王xx",
"TEACHER_TYPE": "员工",
"DATA_UPDATE": "2020-02-04 13:50"
},
{
"NAME": "电影",
"TYPE": "兴趣",
"ACTIVE_TYPE": "社交",
"DATE": "2020-02-04",
"BEGIN_DATE": "09:30",
"END_DATE": "11:45",
"HOURS": "2小时15分钟",
"PERSON": 45,
"JOIN_PERSON": 30,
"SPONSOR": "独立区",
"LABEL": "",
"USE_PLACE": "2号楼多工能厅",
"SCOPE": "课程",
"SON_COURSE": "欣赏课",
"CLUB_NAME": "娱乐",
"TEACHER_NAME": "王xx",
"TEACHER_TYPE": "员工",
"DATA_UPDATE": "2020-02-04 13:50"
}, {
"NAME": "电影",
"TYPE": "兴趣",
"ACTIVE_TYPE": "社交",
"DATE": "2020-02-04",
"BEGIN_DATE": "09:30",
"END_DATE": "11:45",
"HOURS": "2小时15分钟",
"PERSON": 45,
"JOIN_PERSON": 30,
"SPONSOR": "独立区",
"LABEL": "",
"USE_PLACE": "2号楼多工能厅",
"SCOPE": "课程",
"SON_COURSE": "欣赏课",
"CLUB_NAME": "娱乐",
"TEACHER_NAME": "王xx",
"TEACHER_TYPE": "员工",
"DATA_UPDATE": "2020-02-04 13:50"
}, {
"NAME": "电影",
"TYPE": "兴趣",
"ACTIVE_TYPE": "社交",
"DATE": "2020-02-04",
"BEGIN_DATE": "09:30",
"END_DATE": "11:45",
"HOURS": "2小时15分钟",
"PERSON": 45,
"JOIN_PERSON": 30,
"SPONSOR": "独立区",
"LABEL": "",
"USE_PLACE": "2号楼多工能厅",
"SCOPE": "课程",
"SON_COURSE": "欣赏课",
"CLUB_NAME": "娱乐",
"TEACHER_NAME": "王xx",
"TEACHER_TYPE": "员工",
"DATA_UPDATE": "2020-02-04 13:50"
}, {
"NAME": "电影",
"TYPE": "兴趣",
"ACTIVE_TYPE": "社交",
"DATE": "2020-02-04",
"BEGIN_DATE": "09:30",
"END_DATE": "11:45",
"HOURS": "2小时15分钟",
"PERSON": 45,
"JOIN_PERSON": 30,
"SPONSOR": "独立区",
"LABEL": "",
"USE_PLACE": "2号楼多工能厅",
"SCOPE": "课程",
"SON_COURSE": "欣赏课",
"CLUB_NAME": "娱乐",
"TEACHER_NAME": "王xx",
"TEACHER_TYPE": "员工",
"DATA_UPDATE": "2020-02-04 13:50"
}, {
"NAME": "电影",
"TYPE": "兴趣",
"ACTIVE_TYPE": "社交",
"DATE": "2020-02-04",
"BEGIN_DATE": "09:30",
"END_DATE": "11:45",
"HOURS": "2小时15分钟",
"PERSON": 45,
"JOIN_PERSON": 30,
"SPONSOR": "独立区",
"LABEL": "",
"USE_PLACE": "2号楼多工能厅",
"SCOPE": "课程",
"SON_COURSE": "欣赏课",
"CLUB_NAME": "娱乐",
"TEACHER_NAME": "王xx",
"TEACHER_TYPE": "员工",
"DATA_UPDATE": "2020-02-04 13:50"
},
{
"NAME": "电影",
"TYPE": "兴趣",
"ACTIVE_TYPE": "社交",
"DATE": "2020-02-04",
"BEGIN_DATE": "09:30",
"END_DATE": "11:45",
"HOURS": "2小时15分钟",
"PERSON": 45,
"JOIN_PERSON": 30,
"SPONSOR": "独立区",
"LABEL": "",
"USE_PLACE": "2号楼多工能厅",
"SCOPE": "课程",
"SON_COURSE": "欣赏课",
"CLUB_NAME": "娱乐",
"TEACHER_NAME": "王xx",
"TEACHER_TYPE": "员工",
"DATA_UPDATE": "2020-02-04 13:50"
}, {
"NAME": "电影",
"TYPE": "兴趣",
"ACTIVE_TYPE": "社交",
"DATE": "2020-02-04",
"BEGIN_DATE": "09:30",
"END_DATE": "11:45",
"HOURS": "2小时15分钟",
"PERSON": 45,
"JOIN_PERSON": 30,
"SPONSOR": "独立区",
"LABEL": "",
"USE_PLACE": "2号楼多工能厅",
"SCOPE": "课程",
"SON_COURSE": "欣赏课",
"CLUB_NAME": "娱乐",
"TEACHER_NAME": "王xx",
"TEACHER_TYPE": "员工",
"DATA_UPDATE": "2020-02-04 13:50"
}, {
"NAME": "电影",
"TYPE": "兴趣",
"ACTIVE_TYPE": "社交",
"DATE": "2020-02-04",
"BEGIN_DATE": "09:30",
"END_DATE": "11:45",
"HOURS": "2小时15分钟",
"PERSON": 45,
"JOIN_PERSON": 30,
"SPONSOR": "独立区",
"LABEL": "",
"USE_PLACE": "2号楼多工能厅",
"SCOPE": "课程",
"SON_COURSE": "欣赏课",
"CLUB_NAME": "娱乐",
"TEACHER_NAME": "王xx",
"TEACHER_TYPE": "员工",
"DATA_UPDATE": "2020-02-04 13:50"
}, {
"NAME": "电影",
"TYPE": "兴趣",
"ACTIVE_TYPE": "社交",
"DATE": "2020-02-04",
"BEGIN_DATE": "09:30",
"END_DATE": "11:45",
"HOURS": "2小时15分钟",
"PERSON": 45,
"JOIN_PERSON": 30,
"SPONSOR": "独立区",
"LABEL": "",
"USE_PLACE": "2号楼多工能厅",
"SCOPE": "课程",
"SON_COURSE": "欣赏课",
"CLUB_NAME": "娱乐",
"TEACHER_NAME": "王xx",
"TEACHER_TYPE": "员工",
"DATA_UPDATE": "2020-02-04 13:50"
}
]
}
},
}