我是靠谱客的博主 炙热芝麻,这篇文章主要介绍js实现点击下划线跟随的效果!,现在分享给大家,希望可以做个参考。

   闲来无事,写了一个小demo,练一练许久没写的原生js,

具体实现上代码

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<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实现点击下划线跟随内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(90)

评论列表共有 0 条评论

立即
投稿
返回
顶部