* {
margin:0;
padding:0;
}
.num-list-cont {
position:relative;
margin:30px 60px;
border:1px solid #000;
}
.icon-left,.icon-right {
position:absolute;
top:0;
width:30px;
height:30px;
background:deeppink;
cursor:pointer;
}
.icon-left {
left:-35px;
}
.icon-right {
right:-35px;
}
.num-list-box {
position:relative;
height:30px;
overflow:hidden;
}
.num-list {
overflow:hidden;
position:absolute;
left:0;
}
.num-list > li {
list-style:none;
float:left;
width:54px;
height:24px;
line-height:24px;
margin-right:10px;
background:#ccc;
text-align:center;
cursor:pointer;
transition:0.1s all;
}
.num-list > li:hover,.num-list > li.active {
background:#1890ff;
color:#fff;
}
.no-click {
cursor:not-allowed;
opacity:0.3 !important;
pointer-events:none;
}
更新时间:2022-08-02 00:49:43
【思路】
1. 宽度不是定死的,可以根据屏幕自适应
2. 点击后的li居中判断和前后剩余的ul长度与容器的宽度差值有关
3. 左右按钮的判断要分2种,ul<容器框, ul与容器差值>容器框,是否左右顶格也要判断
4. 还是要先分析思路再动笔写,会更清晰,注释可以多写一点没关系