概述
闲来无事,写了一个小demo,练一练许久没写的原生js,
具体实现上代码
<template>
<div class="container">
<div class="content manpower">
<ul class="react-sticky" id="oul">
<li :class="toogleindex === 0 ? 'active' : ''" @click=" getuser(0)">1 tabs</li>
<li :class="toogleindex === 1 ? 'active' : ''" @click="getuser(1)">2 tabs</li>
<li :class="toogleindex === 2 ? 'active' : ''" @click=" getuser(2)">3 tabs</li>
<li :class="toogleindex === 3 ? 'active' : ''" @click="getuser(3)">4 tabs</li>
<li :class="toogleindex === 4 ? 'active' : ''" @click="getuser(4)">5 tabs</li>
<span class="line" ref="boxborder" id="boxborder"></span>
</ul>
<!-- <div></div> -->
</div>
<item-footer/>
</div>
</template>
<script>
import ItemFooter from '@/components/Footer/footer';
// import { setInterval, clearInterval } from 'timers';
// import { getToday ,getToMonth,getPreMontAllDate, getPreMonth } from '@/utils/date'
export default {
name:"manpower",
data() {
return {
toogleindex:0,
flag:true
}
},
components:{
ItemFooter
},
computed:{},
mounted(){
// console.log(getToday())
// console.log(getToMonth())
// console.log(getPreMontAllDate(2))
// console.log(getPreMonth('2019-07-16',12).slice(0,7))
},
methods:{
getuser(num){
var timer
var btn = document.getElementById('boxborder');
var oul = document.getElementById('oul').children[0];
if(this.flag){
this.flag = false;
var btn = document.getElementById('boxborder');
var btnTop = document.getElementById('boxborder').offsetTop;
if(num > this.toogleindex){
timer = setInterval( () => {
if(btnTop >= this.toogleindex * oul.clientHeight){
clearInterval(timer)
this.flag = true;
}else{
btnTop+=4
btn.style.top = btnTop + 'px';
}
},1)
}else{
timer = setInterval( () => {
if(btnTop <= this.toogleindex * oul.clientHeight){
clearInterval(timer)
this.flag = true;
}else{
btnTop-=4
btn.style.top = btnTop + 'px';
}
},1)
}
this.toogleindex = num
}
},
changeHandler(cur) {
// console.log('Z和i')
this.current = cur;
// console.log(cur)
}
}
}
</script>
<style lang="less">
.react-sticky{
width:100px;
margin:100px auto;
position: relative;
li{
background: #fff;
height:50px;
text-align: center;
line-height: 50px;
border-right:1px solid transparent;
&.active{
color:#108ee9;
// border-right: 1px solid #108ee9;
box-sizing: border-box;
// transition: 1s all linear;
}
}
.line{
display: block;
position: absolute;
right:0;
top:0;
width: 2px;
height:50px;
background:#108ee9;
}
}
</style>
最后
以上就是炙热芝麻为你收集整理的js实现点击下划线跟随的效果!的全部内容,希望文章能够帮你解决js实现点击下划线跟随的效果!所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复