视觉冲击:CSS实现相册图片的放大效果,让网站首页更震撼!

简介: 视觉冲击:CSS实现相册图片的放大效果,让网站首页更震撼!

先上效果!

在这个视觉为王的时代,网站的第一屏图片效果尤为关键。一个引人注目的相册放大图片效果不仅能立即吸引访客的注意力,还能提升品牌形象。


代码如下

<div class="wrapper">
  <div class="items">
    <div class="item" tabindex="0" style="background-image: url(https://k.sinaimg.cn/n/sinakd20115/41/w1024h2217/20240406/fa61-836c1e3fe0a39fa9b841b05a6479add9.jpg/w700d1q75cms.jpg)"></div>
    <div class="item" tabindex="0" style="background-image: url(https://img2.baidu.com/it/u=2662780423,1848319877&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=889)"></div>
    <div class="item" tabindex="0" style="background-image: url(https://img1.baidu.com/it/u=1822040938,662611863&fm=253&fmt=auto&app=138&f=JPEG?w=800&h=1201)"></div>
    <div class="item" tabindex="0" style="background-image: url(https://img2.baidu.com/it/u=2662780423,1848319877&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=889)"></div>
    <div class="item" tabindex="0" style="background-image: url(https://n.sinaimg.cn/sinakd20106/600/w1920h1080/20220910/d7b4-bd6c39bbca438f203dbb07f13d709e74.jpg)"></div>
    <div class="item" tabindex="0" style="background-image: url(https://img2.baidu.com/it/u=2662780423,1848319877&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=889)"></div>
    <div class="item" tabindex="0" style="background-image: url(https://img1.baidu.com/it/u=167112264,2214778306&fm=253&fmt=auto&app=120&f=JPEG?w=1067&h=800)"></div>
    <div class="item" tabindex="0" style="background-image: url(https://p2.itc.cn/q_70/images03/20210208/eedbb0ea63d041adb1a94f0bbc721f94.jpeg)"></div>
    <div class="item" tabindex="0" style="background-image: url(https://pic3.zhimg.com/50/v2-7fce7f53fd8dc4d5c87a333d1da15bf6_hd.jpg)"></div>
    <div class="item" tabindex="0" style="background-image: url(https://img0.baidu.com/it/u=1751786893,3026131290&fm=253&fmt=auto&app=138&f=JPEG?w=800&h=1200)"></div>
    <div class="item" tabindex="0" style="background-image: url(https://pic1.zhimg.com/v2-fbe957fcc055e34ebc949ef3fdb560ee_r.jpg?source=1940ef5c)"></div>
    <div class="item" tabindex="0" style="background-image: url(https://n.sinaimg.cn/sinacn21/500/w1200h900/20180324/0325-fysnevm7150027.jpg)"></div>
    <div class="item" tabindex="0" style="background-image: url(https://wx3.sinaimg.cn/large/007xWHp9ly1gr0hpovb0fj30qo0qoaqw.jpg5)"></div>
      
    </div>
      
    </div>
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}
:root{
    --index: calc(1vw + 1vh);
    --transition: cubic-bezier(.1, .7, 0, 1);
}
body{
    background-color: #141414;
}
.wrapper{
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
}
.items{
    display: flex;
    gap: 0.4rem;
    perspective: calc(var(--index) * 35);
}
.item{
    width: calc(var(--index) * 3);
    height: calc(var(--index) * 12);
    background-color: #222;
    background-size: cover;
    background-position: center;
    cursor: pointer;
    filter: grayscale(1) brightness(.5);
    transition: transform 1.25s var(--transition), filter 3s var(--transition), width 1.25s var(--transition);
    will-change: transform, filter, rotateY, width;
}
  
.item::before, .item::after{
    content: '';
    position: absolute;
    height: 100%;
    width: 20px;
    right: calc(var(--index) * -1);
}
.item::after{
    left: calc(var(--index) * -1);
}
.items .item:hover{
    filter: inherit;
    transform: translateZ(calc(var(--index) * 10));
}
/*Right*/
.items .item:hover + *{
    filter: inherit;
    transform: translateZ(calc(var(--index) * 8.5)) rotateY(35deg);
    z-index: -1;
}
.items .item:hover + * + *{
    filter: inherit;
    transform: translateZ(calc(var(--index) * 5.6)) rotateY(40deg);
    z-index: -2;
}
.items .item:hover + * + * + *{
    filter: inherit;
    transform: translateZ(calc(var(--index) * 2.5)) rotateY(30deg);
    z-index: -3;
}
.items .item:hover + * + * + * + *{
    filter: inherit;
    transform: translateZ(calc(var(--index) * .6)) rotateY(15deg);
    z-index: -4;
}
/*Left*/
.items .item:has( + :hover){
   filter: inherit;
    transform: translateZ(calc(var(--index) * 8.5)) rotateY(-35deg);
}
.items .item:has( + * + :hover){
    filter: inherit;
    transform: translateZ(calc(var(--index) * 5.6)) rotateY(-40deg);
}
.items .item:has( + * + * + :hover){
   filter: inherit;
    transform: translateZ(calc(var(--index) * 2.5)) rotateY(-30deg);
}
.items .item:has( + * + * + * + :hover){
    filter: inherit;
    transform: translateZ(calc(var(--index) * .6)) rotateY(-15deg);
}
.items .item:active, .items .item:focus {
    width: 28vw;
    filter: inherit;
    z-index: 100;
    transform: translateZ(calc(var(--index) * 10));
    margin: 0 .45vw;
}
相关文章
|
23天前
|
前端开发
导航新风尚:CSS梯形设计,让网站菜单不再单调!
导航新风尚:CSS梯形设计,让网站菜单不再单调!
|
23天前
|
前端开发
视觉充电:CSS动画特效,为网站带来动力与活力!(一键复制)
视觉充电:CSS动画特效,为网站带来动力与活力!(一键复制)
|
1月前
|
前端开发
如何使用 CSS object-fit 进行图片的缩放和裁剪
如何使用 CSS object-fit 进行图片的缩放和裁剪
48 0
如何使用 CSS object-fit 进行图片的缩放和裁剪
|
14天前
|
前端开发 JavaScript 搜索推荐
打造个人博客网站:从零开始的HTML、CSS与JavaScript之旅
在这个数字时代,拥有一个个性化的网络空间已成为许多人的梦想。本文将引导你了解如何从零开始,使用HTML、CSS和JavaScript创建属于自己的博客网站。我们将探索这些技术的基础概念,并通过实际代码示例展示如何将静态页面转变为动态交互式网站。无论你是编程新手还是希望扩展技能的开发者,这篇文章都将为你提供一条清晰的学习路径。【8月更文挑战第31天】
|
2月前
|
前端开发 容器
CSS【详解】对齐 (含文本垂直对齐,文本水平对齐、单行文本垂直居中、多行文本垂直居中、6 种方案块级元素水平垂直居中 、7 种方案图片水平垂直居中、文本自适应对齐、图标和文本对齐,图片和文本对齐等)
CSS【详解】对齐 (含文本垂直对齐,文本水平对齐、单行文本垂直居中、多行文本垂直居中、6 种方案块级元素水平垂直居中 、7 种方案图片水平垂直居中、文本自适应对齐、图标和文本对齐,图片和文本对齐等)
41 0
|
2月前
|
前端开发 C++
css 鼠标悬浮显示放大图片 vs 鼠标点击显示放大图片
css 鼠标悬浮显示放大图片 vs 鼠标点击显示放大图片
28 0
|
2月前
|
前端开发
前端 CSS 经典:图层放大的 hover 效果
前端 CSS 经典:图层放大的 hover 效果
28 0
|
2月前
|
前端开发 UED
前端 CSS 经典:在 Vue3 中使用渐进式图片
前端 CSS 经典:在 Vue3 中使用渐进式图片
63 0
|
2月前
|
前端开发
前端 CSS 经典:图片边框
前端 CSS 经典:图片边框
19 0
|
前端开发
一些上流的CSS3图片样式 | CSS | 前端观察
来源:http://www.qianduan.net/css3-image-styles.html#jtss-hi
738 0