一捏捏js+HTML+CSS小实例(干净清爽版个人主页)

效果展示:

进入页面:

 点击右上角展开目录:

代码展示:

HTML代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>个人主页</title>
    <link rel="stylesheet" href="style.css">
</head>
<body>
<div class="bg">
    <div class="txt">Welcome to<br><span>My personal homepage</span></div>
    <div class="menu">
<!--        右上角展开栏-->
        <div class="cross">
            <span class="dash1"></span>
            <span class="dash2"></span>
        </div>
<!--        展开背景-->
        <div class="circle"></div>
<!--        展开内容部分-->
        <div class="options">
            <ul>
                <li><a href="#">About</a></li>
                <li><a href="#">Home</a></li>
                <li><a href="#">Services</a></li>
                <li><a href="#">Contact Us</a></li>
            </ul>
        </div>
    </div>
</div>

<script src="script.js"></script>
</body>
</html>

CSS代码:

/*google字体库*/
@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@700&display=swap');

*{
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: roboto;
    overflow: hidden;
}

.bg{
    width:100%;
    height: 100vh;
    background: linear-gradient(135deg,#22242f,#033344);
    background-size: cover;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
}

.txt{
    position: absolute;
    color: #fff;
    font-size: 3rem;
    text-transform: uppercase;
    line-height: 55px;
}

.txt span{
    font-size: 5rem;
    position: relative;
}

.menu{
    position: absolute;
    width: 100%;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
}

.circle{
    position: absolute;
    right: 0;
    top: 0;
    width: 5rem;
    height: 5rem;
    background-color: #1a94b5;
    border-bottom-left-radius: 100%;
    transition: all 0.5s ease-in-out;
}

.cross{
    position: absolute;
    top: 0.6rem;
    right: 0.6rem;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    width: 40px;
    height: 40px;
    z-index: 3;

}

.dash1{
    position: relative;
    width: 100%;
    height: 0.25rem;
    background-color: #fff;
    border-radius: 25px;
    transition: all 0.25s ease-in-out;
}

.dash2{
    position: relative;
    transform: translateY(5px);
    background-color: #fff;
    width: 40%;
    height: 0.25rem;
    left: 10px;
    border-radius: 25px;
    transition: all 0.25s ease-in-out;
}
/*如果cross元素存在open类名时,则cross元素中的dash1元素变形*/
.cross.open .dash1{
    transform: rotate(-45deg) translate(-3px,2px);
}
/*如果cross元素存在open类名时,则cross元素中的dash2元素变形*/
.cross.open .dash2{
    transform: rotate(45deg) translate(-6px,7px);
    width: 100%;
}
/*如果cross元素存在open类名时,则cross后方的所有circle元素将被展开*/
.cross.open ~ .circle{
    width: 150%;
    height: 150vh;
    border-bottom-left-radius: 100%;
}

.options{
    width: 100%;
    height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    opacity: 0;
    transition: all 0.2s ease-in-out;
    transition-delay: 0.25s;
    z-index: 2;
}
/*如果cross元素存在open类名时,则cross后方的所有options元素的内容将变得不透明*/
.cross.open ~ .options{
    opacity: 1;
}

.options ul{
    text-align: center;
}
.options ul li{
    width: 100%;
    height: auto;
}
.options ul li a{
    text-decoration: none;
    font-size: 2.2rem;
    color: #fff;
    text-transform: uppercase;
    letter-spacing: 1px;
}

JS代码:

let cross = document.getElementsByClassName("cross")[0];
//当cross元素被点击时为cross元素添加open类名,再次点击时将隐藏open类名
cross.addEventListener("click",function () {
cross.classList.toggle("open");
})

参考:b站up主 叫我凤凰Blanco

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值