• 【css】用纯 CSS 判断鼠标进入的方向


    代码

    <style>
        body {
            padding: 2em;
            text-align: center;
        }
        .block {
            position: relative;
            display: inline-block;
            overflow:hidden;
             10em;
            height: 10em;
            vertical-align: middle;
            transform: translateZ(0);
        }
        .block_hoverer {
            position: absolute;
            z-index: 1;
             100%;
            height: 100%;
            opacity: 0;
            transition: all .3s ease;
        }
    
        .block_hoverer:nth-child(1) {
            background: red;
            top: -90%;
        }
    
        .block_hoverer:nth-child(2) {
            background: lime;
            top: 90%;
        }
    
        .block_hoverer:nth-child(3) {
            background: orange;
            left: -90%;
        }
    
        .block_hoverer:nth-child(4) {
            background: blue;
            left: 90%;
        }
        .block_hoverer:hover {
            opacity: 1;
            top: 0;
            left: 0;
        }
    
        .block_content {
            position: absolute;
            top: 0;
            left: 0;
             100%;
            height: 100%;
            text-align: center;
            line-height: 10em;
            background: #333;
            color: #FFF;
        }
    </style>
    <body>
        <p class="text">从不同方向使鼠标指针移过下面的内容</p>
        <p>↓</p>
        <span>→ </span>
        <div class="block">
            <div class="block_hoverer">1</div>
            <div class="block_hoverer">2</div>
            <div class="block_hoverer">3</div>
            <div class="block_hoverer">4</div>
            <div class="block_content">
                Hover me!
            </div>
        </div>
        <span> ←</span>
        <p>↑</p>
    </body>
    
    

    效果:

  • 相关阅读:
    惊讶
    BLOG休假
    因考试得福
    Shape of My HeartSting !
    一个月的第一天了
    BLOG开张喽~~~
    该走了
    脏话
    EditText的属性
    游戏引擎
  • 原文地址:https://www.cnblogs.com/richerdyoung/p/12911738.html
Copyright © 2020-2023  润新知