zoukankan      html  css  js  c++  java
  • CSS实战笔记(七) 全屏切换

    1、效果演示

    2、完整代码

    index.html

    <!DOCTYPE html>
    <html>
    <head>
        <title>Full-Screen Toggle</title>
        <link type="text/css" rel="stylesheet" href="index.css" />
    </head>
    <body>
        <div class="page-wrapper" id="page-wrapper">
            <div class="page-content content-0"></div>
            <div class="page-content content-1"></div>
            <div class="page-content content-2"></div>
        </div>
        <div class="page-tap" id="page-tap">
            <div class="side-tap tap-0" data-index="0"></div>
            <div class="side-tap tap-1" data-index="1"></div>
            <div class="side-tap tap-2" data-index="2"></div>
        </div>
        <div class="page-hint" id="page-hint"></div>
        <script type="text/javascript" src="index.js"></script>
    </body>
    </html>
    

    index.css

    html, body {
        margin: 0;
        padding: 0;
         100%;
        height: 100%;
        overflow: hidden;
    }
    .page-wrapper {
         100%;
        position: absolute;
        left: 0;
        top: 0;
        transition: top 600ms ease-out;
    }
    .page-content {
         100%;
    }
    .content-0 {
        background-color: rgba(236, 0, 140, 0.2);
    }
    .content-1 {
        background-color: rgba(38, 230 ,0, 0.2);
    }
    .content-2 {
        background-color: rgba(68, 200 ,245, 0.2);
    }
    .page-tap {
        position: fixed;
        top: 0%;
        left: 96%;
         4%;
        display: flex;
        flex-direction: column;
        background-color: white;
    }
    .side-tap {
        flex: 1;
    }
    .side-tap:hover {
        cursor: pointer;
        opacity: 0.4;
    }
    .tap-0 {
        background-color: #ec008c;
        opacity: 0.2;
    }
    .tap-1 {
        background-color: #26e600;
        opacity: 0.2;
    }
    .tap-2 {
        background-color: #44c8f5;
        opacity: 0.2;
    }
    .page-hint {
        position: fixed;
        top: 90%;
        left: 50%;
        animation: arrow-down 1200ms ease-out infinite;
    }
    .page-hint::before {
        content: "";
        position: absolute;
         10px;
        height: 10px;
        border-top: 1px solid gray;
        border-left: 1px solid gray;
        transform: rotate(-135deg);
    }
    .page-hint::after {
        content: "";
        position: absolute;
         10px;
        height: 10px;
        border-top: 1px solid gray;
        border-left: 1px solid gray;
        transform: rotate(-135deg);
        margin-top: 10px;
    }
    @keyframes arrow-down {
        from { transform: translateY(0px); opacity: 0.5; }
        to { transform: translateY(25px); opacity: 0; }
    }
    

    index.js

    let clientHeight = document.body.clientHeight
    let wrapper = document.getElementById('page-wrapper')
    let tap = document.getElementById('page-tap')
    let hint = document.getElementById('page-hint')
    let pages = document.getElementsByClassName('page-content')
    let totalPages = pages.length
    
    wrapper.style.height = clientHeight + 'px'
    tap.style.height = clientHeight + 'px'
    for (let currIndex = 0; currIndex < totalPages; currIndex++) {
        pages[currIndex].style.height = clientHeight + 'px'
    }
    
    let currActiveListener = {
        value: 0,
        get currActive() {
            return this.value
        },
        set currActive(value) {
            this.value = value
            wrapper.style.top = -(value * clientHeight) + 'px'
            hint.style.display = (value === totalPages - 1) ? 'none' : 'block'
        }
    }
    
    let currTimer = 0
    let lastTimer = 0
    document.addEventListener('mousewheel', function(event) {
        currTimer = new Date().getTime()
        if (currTimer - lastTimer > 300) {
            if (event.wheelDelta < 0 && currActiveListener.currActive < totalPages - 1) {
                currActiveListener.currActive += 1
            }
            if (event.wheelDelta > 0 && currActiveListener.currActive > 0) {
                currActiveListener.currActive -= 1
            }
            lastTimer = new Date().getTime()
        }
    })
    
    document.getElementById('page-hint').addEventListener('click', function(){
        currActiveListener.currActive = (currActiveListener.currActive + 1) % totalPages
    })
    
    document.getElementById('page-tap').addEventListener('click', function(){
        currActiveListener.currActive = parseInt(window.event.path[0].getAttribute('data-index'))
    })
    

    【 阅读更多 CSS 系列文章,请看 CSS学习笔记

    版权声明:本博客属于个人维护博客,未经博主允许不得转载其中文章。
  • 相关阅读:
    同一内网不能网段ping 不通
    mysql 5.6.33 重置密码后报错
    设置tomcat内存设定
    python 取两数的百分比
    cache buffers
    登录到mysql查看binlog日志
    mysqlbinlog 查看日志时发生报错
    find 查找文件 -exec 然后压缩 查看tar包的内容
    zip 压缩文件 unzip查看zip压缩包内的内容
    react-native 完整实现登录功能
  • 原文地址:https://www.cnblogs.com/wsmrzx/p/11818537.html
Copyright © 2011-2022 走看看