移动端页面切换效果(基于动画transform)

效果一览:
transform_01
思路:
所有的视图采用绝对定位absoulte一同悬浮于文档流相同的位置,并通过transform: translateX(-100%)隐藏于X轴左部,当前视图锚点触发时,让当前视图transformX(0px)沿X轴移动到原点处进行显示。移动过程中通过transition: all 1s控制移动速度,使其在移动过程中明显看到页面的切换效果。
实现代码:
html

<main>
    <div id="home">
        <i class="fa fa-home" aria-hidden="true"></i>
    </div>
    <div id="video">
        <i class="fa fa-vimeo" aria-hidden="true"></i>
    </div>
    <div id="my">
        <i class="fa fa-viadeo" aria-hidden="true"></i>
    </div>
</main>
<nav>
    <a href="#home">home</a>
    <a href="#video">video</a>
    <a href="#my">my</a>
</nav>

css

* {
    padding: 0;
    margin: 0;
    box-sizing: border-box;
}

body {
    width: 100vw;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

main {
    flex: 1;
    position: relative;
}

nav {
    width: 100%;
    height: 6vh;
    background-color: #34495e;
    display: flex;
    justify-content: space-evenly;
    align-items: center;
    text-align: center;
}

nav a {
    text-decoration: none;
    color: white;
    font-size: 1.5em;
    text-transform: uppercase;
    flex: 1;
    font-weight: 700;
}

nav a:nth-child(2) {
    border-right: 1px solid #aaa;
    border-left: 1px solid #aaa;
}

main > div {
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    transition: all 1s;
    transform: translateX(-100%);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    font-size: 2em;
}

main>div:target {
    transform: translateX(0px);
}

main>div:nth-of-type(1):target {
    background: #0984e3;
}

main>div:nth-of-type(2):target {
    background: #fab1a0;
}

main>div:nth-of-type(3):target {
    background: #fdcb6e;
}

div i[class^="fa"] {
    font-size: 100px;
    color: white;
}
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值