css動畫之clip

先看效果
先看效果

clip 屬性剪裁絕對定位元素。
當一幅圖像的尺寸大於包含它的元素時會發生什麼呢?"clip" 屬性允許您規定一個元素的可見尺寸,這樣此元素就會被修剪並顯示爲這個形狀。

clip: rect(<top>, <right>, <bottom>, <left>);

圖片描述

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title></title>
    <style type="text/css">
        .box {
            margin: 100px;
            display: inline-block;
            padding: 8px;
            position: relative;
            background-color: rgba(255,255,255,0.8);
        }
        .box::before {
            content: '';
            position: absolute;
            left: 0;
            top: 0;
            right: 0;
            bottom: 0;
            border: 2px solid #E611F1;
            animation: borderAround 5s infinite linear;
            background-color: rgba(25,66,25,0.8);
        }
        @keyframes borderAround {
            0%,
            100% {
                clip: rect(0 148px 2px 0);
            }
            25% {
                clip: rect(0 148px 116px 146px);
            }
            50% {
                clip: rect(116px 148px 116px 0);
            }
            75% {
                clip: rect(0 2px 116px 0);
            }
        }
    </style>
</head>

<body>
    <div class="box">
        <img src="img/15177108659009550.gif" width="128" height="96" style="background-color: white;">
    </div>
</body>
</html>

附送一張解密圖

圖片描述

*借鑑張鑫旭博文

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章