沉浸式阅读
Beta
转载

JS下划线跟随tab选项卡

     订阅 JS相关     2019-02-25     733    0    0    0    2019-02-25
学习要点:效果图 HTMLdiv class="nav"ullidon(0)"翠翠/lilidon(1)"嗯嗯/lilidon(2)"小白/lilidon(3)"小沫/lilidon(4)"同同/li/ul/divdiv class="tiao"div id="zhou" class="zhou" style="left: 0;"div class="ww&

效果图


HTML



<div class="nav">
    <ul>
        <lidon(0)">翠翠</li>
        <lidon(1)">嗯嗯</li>
        <lidon(2)">小白</li>
        <lidon(3)">小沫</li>
        <lidon(4)">同同</li>
    </ul>
</div>

<div class="tiao">

    <div id="zhou" class="zhou" style="left: 0;">
        <div class="ww"></div>
    </div>
</div>

<div id="nei" class="nei">
    <ul>
        <li style="background-color:#e4007f; display: block;">最猪的BOSS</li>
        <li style="background-color:#687de8">最萌的BOSS</li>
        <li style="background-color:#2fb936">最蠢的BOSS</li>
        <li style="background-color:#4dd5d0">最萌的BOSS</li>
        <li style="background-color:#e24759">最帅的BOSS</li>
    </ul>

</div>



CSS


* {
	margin:0;
	margin:0;
	padding:0;
	list-style:none;
}
.nav {
	width:100%;
	height:50px;
}
.nav ul {
	width:600px;
	height:50px;
	margin:0 auto;
}
.nav ul li {
	width:120px;
	height:50px;
	font-weight:800;
	font-size:18px;
	color:#515151;
	line-height:50px;
	text-align:center;
	float:left;
	cursor:pointer;
}
.tiao {
	width:600px;
	height:5px;
	background-color:#515151;
	margin:0 auto;
	position:relative;
	top:0;
	left:0;
}
.zhou {
	width:120px;
	height:5px;
	background-color:red;
	position:absolute;
	top:0;
	left:0;
}
.ww {
	width:0px;
	border-width:8px;
	border-style:solid;
	border-color:rgba(250,0,255,0) rgba(250,0,255,0) red rgba(250,0,255,0);
	position:absolute;
	top:-16px;
	left:56px;
}
.nei {
	width:600px;
	height:300px;
	margin:0 auto;
}
.nei li {
	width:600px;
	height:300px;
	color:#fff;
	font-family:"微软雅黑";
	font-size:40px;
	text-align:center;
	line-height:300px;
	display:none;
	margin-top:10px;
}

JS


var k;
var kk = 0;

function don(gh) {
    if (kk == 0) {
        kk = 1
        var w1 = document.getElementById('zhou')
        var t = parseInt(w1.style.left)

        if (t < gh * 120) {
            k = window.setInterval(
                function() {
                    goright(gh * 120)
                }, 30

            )
        } else if (t > gh * 120) {
            k = window.setInterval(
                function() {
                    goleft(gh * 120)
                }, 30

            )
        } else {
            kk = 0
        }


        var w2 = document.getElementById('nei').getElementsByTagName('li')
        for (var i = 0; i < w2.length; i++) {
            w2[i].style.display = "none"
        }

        w2[gh].style.display = "block"

    }




}




//右移动
function goright(gh1) {
    var w1 = document.getElementById('zhou')
    var t = parseInt(w1.style.left)
    t += 20

    if (t >= gh1) {
        t = gh1
        window.clearInterval(k)
        kk = 0
    }
    w1.style.left = t + "px"
}


//左移动

function goleft(gh1) {
    var w1 = document.getElementById('zhou')
    var t = parseInt(w1.style.left)
    t -= 20
    //alert(t)
    if (t <= gh1) {
        t = gh1
        window.clearInterval(k)
        kk = 0
    }
    w1.style.left = t + "px"
}

提示: jQuery调用版本:1.11.3

本文标题: JS下划线跟随tab选项卡

本文链接: https://www.mbkfw.com/course/641.html (转载时请注明来源链接)

本文说明: 有问题或投稿请发送至: 邮箱/kf@dtmuban.com    QQ/290948585

特别鸣谢: 如果您觉得本文对您有帮助,请给我们一个小小的赞,收藏本文更利于反复学习哦!

 
本文标签: #下划线 #tab #选项卡
destoon程序前端开发标签生成器

下班PC阅读不方便?

手机也可以随时学习开发

微信关注公众号“商企云服”
"模板开发网前端开发教学"
每日干货技术分享
 
0

圈友点评

文明上网理性发言,请遵守网络评论服务协议

小编推荐



色彩
×

《客户实名在线注册登记》售后一直都在!

关注

微信
关注

微信扫一扫
不同的环境体验

幸运大转盘,好礼等您拿

模板开发网公众号

模板开发网微信小程序

代授权

程序
授权

黑小二

联系
客服

很高兴为您服务
尊敬的用户,欢迎您咨询,我们为新用户准备了优惠好礼。咨询客服

联系客服:

在线QQ: 290948585

客服电话: 18605917465

E_mail邮箱: kf@dtmuban.com

微信公众号: 商企云服

微信小程序: 模板开发

QQ客服 微信客服DT授权代办 在线交谈 智能小云

工作时间:

周一至周五: 09:00 - 18:00

APP下载

安卓
APK

模板开发网安卓版APP

反馈

我要
反馈