学堂 学堂 学堂公众号手机端

微信朋友圈展开收起特效

lewis 1年前 (2024-03-05) 阅读数 2 #技术

欢迎大家留言讨论

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>

    <style>
        .wrapper {
            margin: 50px auto;
            width: 400px;
            overflow: hidden;
            border-radius: 8px;
            padding: 15px;
            box-shadow: 20px 20px 60px #bebebe,
                -20px -20px 60px #ffffff;
        }

        .text {
            font-size: 20px;
            overflow: hidden;
            text-overflow: ellipsis;
            text-align: justify;
            position: relative;
            line-height: 1.5;
            max-height: 4.5em;
            transition: .3s max-height;

        }

        .btn {
            float: left;
            color: aqua;
        }

        .btn::after {
            font-size: 20px;
            content: '全文';
        }

        .exp {
            display: none;
        }

        .exp:checked+.text {
            max-height: none;
        }

        .exp:checked+.text+.btn::after {
            content: '收起';
        }

        .btn.hidden {
            display: none;
        }
    </style>
</head>

<body>
    <div class="wrapper">
        <input type="checkbox" id="exp1" class="exp">
        <div class="text">
            浮动元素是如何定位的
            正如我们前面提到的那样,当一个元素浮动之后,它会被移出正常的文档流,然后向左或者向右平移,一直平移直到碰到了所处的容器的边框,或者碰到另外一个浮动的元素。
            正如我们前面提到的那样,
        </div>
        <label class="btn" for="exp1"></label>
    </div>

    <script>
        const el = document.querySelector('.text')
        if (el.scrollHeight <= el.clientHeight) {
            document.querySelector('.btn').classList.add('hidden')
        }
    </script>
</body>

</html>
版权声明

本文仅代表作者观点,不代表博信信息网立场。

热门