【JavaScript】纯CSS蜂巢式图片画廊效果
jQuery发表于:2024-11-06 12:00:35浏览:238次
这是一款纯CSS蜂巢式图片画廊效果。该CSS蜂巢式图片画廊通过CSS网格布局,将图片以蜂巢的六边形进行布局,非常炫酷。
HTML代码
<div class="container" style="--n-rows: 3; --n-cols: 6">
<style>.hex-cell:nth-of-type(5n + 1) { grid-column-start: 2 }</style>
<div class="hex-cell"><img src="./img/1.jpg"/></div>
<div class="hex-cell"><img src="./img/2.jpg"/></div>
<div class="hex-cell"><img src="./img/3.jpg"/></div>
<div class="hex-cell"><img src="./img/4.jpg"/></div>
<div class="hex-cell"><img src="./img/5.jpg"/></div>
<div class="hex-cell"><img src="./img/6.jpg"/></div>
<div class="hex-cell"><img src="./img/7.jpg"/></div>
</div>
CSS代码
.container {
--l: calc(100vw/var(--n-cols));
--hl: calc(.5*var(--l));
--ri: calc(.5*1.73205*var(--l));
box-sizing: border-box;
display: grid;
place-content: center;
grid-template: repeat(var(--n-rows), var(--l))/repeat(var(--n-cols), var(--ri));
grid-gap: var(--hl) 0;
overflow: hidden;
margin: 0;
padding: var(--hl) 0;
height: 100vh;
background: #262626;
filter: drop-shadow(2px 2px 5px);
}
@media (orientation: landscape) {
.container {
--l: calc(100vh/(var(--n-rows) + 3));
}
}
.hex-cell {
overflow: hidden;
grid-column-end: span 2;
margin: calc(-1*var(--hl)) 0;
transform: scale(0.95);
clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%);
}
img {
--hl: 0;
width: 100%;
height: 100%;
object-fit: cover;
transform: scale(calc(1 + .2*var(--hl)));
filter: brightness(calc(.6*(1 + var(--hl))));
transition: .7s;
}
img:hover {
--hl: 1;
}
猜你喜欢
- 【JavaScript】javascript中doucument对象的属性和方法有哪些
- doucument对象的属性和方法有:body、cookie、domain、lastmodified、referrer、title、close()、open()、write()、getelementbyid()、normalize()等等。本教程操作环境:windows7系统、javascript1.8.5版、Dell G3电脑。Document 对象每个载入浏览器的 HTML 文档都会成为 Document 对象。Document 对象使我们可以从脚本中对 HTML 页面中的所有元素进行访问。
- 【JavaScript】字母大小写转换的JS方法
- 1. toUpperCase() 方法:将字符串中的所有字母转换为大写。例如,`"hello world".toUpperCase()` 将返回 `"HELLO WORLD"`。
- 【JavaScript】JS中referer的使用
- HTTP请求中有一个referer的报文头,用来指明当前流量的来源参考页。例如在www.sina.com.cn/sports/上点击一个链接到达cctv.com首页,那么就referrer就是www.sina.com.cn/sports/了。在Javascript中,我们可以通过document.referrer来获取同样的信息。通过这个信息,我们就可以知道访客是从什么渠道来到当前页面的。这对于Web Analytics来说,是非常重要的,这可以告诉我们不同渠道带来的流量的分布情况,还有用户搜索
- 【JavaScript】JS获取时间并格式化
- 方法一:使用JavaScript的Date对象和相关方法来获取时间并格式化var now = new Date(); // 格式化日期 var year = now.getFullYear(); var month = (now.getMonth() + 1 < 10 ? "0"&nbs
- 【Javascript】CSS3和js超酷iPhone样式科学计算器插件
- CalcSS3是一款非常酷的CSS3和js模仿iPhone样式科学计算器插件。该计算器插件没有使用图片,纯CSS制作。该计算器是科学型的,可以处理乘方、开方、指数、对数等复杂的数学运算。
- 【JavaScript】JS生成二维码-qrcode.js
- 二维码又称QRCode,是一个近几年来移动设备上很流行的一种编码方式它比传统的一维码(条形码)能存更多的信息,也能表示更多的数据类型。按照一定规律排列组成的几何图形构成,它巧妙地利用构成计算机内部逻辑...
- 【JavaScript】如何从 JavaScript 数组中删除重复元素?
- 在 JavaScript 中,有多种方法可以从数组中删除重复元素。在本文中,我们将探讨一些删除重复元素的顶级方法。使用filter()方法filter()方法使用传递的条件创建一个新的元素数组。这将仅包含作为此过滤器方法的一部分返回 true 的元素。因此,要实现删除重复元素,我们只需在 filter() 方法中添加条件即可,它会完成剩下的工作。#过滤器.js<script> var arr = ["stev
- 【JavaScript】JS时间和时间戳互转
- 在JavaScript中,获取当前时间的时间戳(秒值)可以使用 Date.now() 方法,而将时间戳转换为日期格式可以使用 Date 对象。获取当前时间戳(秒值):let timestampSeconds = Date.now() / 1000; console.log(timestampSeconds); // 输出的是以秒为单位的时间戳将时间戳转换为日期:let timestampSeconds =&
栏目分类全部>