图片放大 demo

效果

这里写图片描述

思路

1.设置4个div

<div class="cards">
    <div class="red"></div>
    <div class="blue"></div>
    <div class="purple"></div>
    <div class="brown"></div>
</div>

2.设置伪元素after,用于实现阴影效果

 .cards > div:after {
            content: "";
            background: inherit;
            filter: blur(.9em);
            opacity: 0;
            height: 20%;
            width: 70%;
            position: absolute;
            margin-left: auto;
            margin-right: auto;
            left: 0;
            right: 0;
            bottom: 0;
            transition: opacity 1s, bottom 0.5s;
        }

3.设置hover,用transition实现动画过渡效果

 .cards > div:hover:after {
            opacity: .8;
            bottom: -1.2em;
        }

源码

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>图片放大</title>
    <style>
        .cards {
            margin: auto;
            padding: 1em;
            background: white;
            width: 640px;
        }


        .red { background: tomato; }
        .blue { background: steelblue; }
        .purple { background: mediumpurple; }
        .brown { background: rosybrown; }

        .cards > div {
            margin: 2em;
            width: 250px;
            height: 250px;
            display: inline-block;
            position: relative;
            transition: transform 0.5s;
        }

        .cards > div:hover {
            transform: scale(1.2);
            cursor: pointer;
        }

        .cards > div:after {
            content: "";
            background: inherit;
            filter: blur(.9em);
            opacity: 0;
            height: 20%;
            width: 70%;
            position: absolute;
            margin-left: auto;
            margin-right: auto;
            left: 0;
            right: 0;
            bottom: 0;
            transition: opacity 1s, bottom 0.5s;
        }

        .cards > div:hover:after {
            opacity: .8;
            bottom: -1.2em;
        }
    </style>
</head>
<body>
<div class="cards">
    <div class="red"></div>
    <div class="blue"></div>
    <div class="purple"></div>
    <div class="brown"></div>
</div>
</body>
</html>

参考

http://codepen.io/dhanishgajjar/pen/OmZbgL

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值