css实现自适应图片相册滚动闪现入场动画效果代码
代码语言:html
所属分类:画廊相册
代码描述:css实现自适应图片相册滚动闪现入场动画效果代码,往下滚动鼠标试试。
代码标签: css 自适应 图片 相册 滚动 闪现 入场 动画
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> <style> @import url("https://fonts.googleapis.com/css2?family=Gochi+Hand&family=Handlee&display=swap"); @property --i0 { syntax: "<number>"; initial-value: 0; inherits: true; } @property --o0 { syntax: "<number>"; initial-value: 0; inherits: true; } @property --i1 { syntax: "<number>"; initial-value: 0; inherits: false; } @property --o1 { syntax: "<number>"; initial-value: 0; inherits: false; } * { margin: 0; } html, body, header, main, figure, footer { display: grid; } body { background: #212121; color: #ededed; font: 1.25em handlee, cursive; font-size: clamp(.75em, 1vw + 1vh, 1.25em); } header, main, footer { grid-gap: 0.5em; padding: 0.5em; min-height: 100vh; } header, footer { grid-template-columns: min(100%, 62em); place-content: center; text-align: center; text-wrap: balance; } h1 { font: 3em gochi hand, cursive; } main { grid-template-columns: repeat(auto-fill, minmax(min(20em, 100%), 1fr)); /* limit width, avoid horizontal scrollbar??? */ width: min(96em, 100% - 2 * 0.5em); } figure { /* avoid image making grid overflow figure */ grid-template: 100%/100%; aspect-ratio: 3/2; animation: a 1s both; animation-name: i, o; animation-timeline: view(); animation-range: entry 0% entry 0%, exit 100% exit 100%; } figure:hover { --hov: 1 ; } @keyframes i { to { --i0: 1 ; } } @keyframes o { to { --o0: 1 ; } } img, figcaption { grid-area: 1/1; } img { --i1: var(--i0); --o1: var(--o0); /* aspect-ratio here doesn't seem to work in Firefox? */ width: 100%; height: 100%; object-fit: cover; box-shadow: 2px 2px 5px #0007; transition: --i1 0.3s ease-out, --o1 0.3s ease-in; animation: p 1s cubic-bezier(0.32, 0, 0.68, 0) both; animation-timeline: view(); animation-range: entry 0% exit 100%; /* so they don't get applied in non-supporting browsers */ } @supports (animation-range: exit 0% exit 0%) { img { scale: calc(var(--i1) - var(--o1)); opacity: calc(var(--i1)*(1 - var(--o1))); } } @keyframes p { 0% { object-position: 50% 0; } 50% { object-position: 50%; animation-timing-function: cubic-bezier(0.32, 1, 0.68, 1); } 100% { object-position: 50% 100%; } } figcaption { place-self: end; z-index: 1; margin: 0.5em; padding: 0.5em; opacity: var(--hov, 0); background: #212121ab; transition: opacity 0.3s; } a { color: gold; } /* styling support info boxes */ aside { position: fixed; /* prevent it from scrolling */ z-index: 2; inset: auto 0 0; } .box { margin: 1em; border-left: solid 5px #dc3055; padding: 1em; box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.35); background: #851d40; color: #fff; font: 1.25em/1.25 ubuntu, trebuchet ms, arial, sans-serif; } @supports (animation-range: exit 0% exit 0%) { .box { display: none; } } code { padding: 2px; background: rgba(0, 0, 0, 0.35); font: 1.1em/1.2 ubuntu mono, consolas, monaco, monospace; } </style> </head> <body translate="no"> <header> <h1>Pure CSS simple gallery with on scroll effects - reveal, parallax. Responsive, accssible.</h1> </header> <main> <figure><img src="//repo.bfw.wiki/random/400x300/景色?rand=1"/> <figcaption>photo by <a href="" target="_blank">auther</a></figcaption> </figure> <figure><img src="//repo.bfw.wiki/random/400x300/景色?rand=2"/> <figcaption>photo by <a href="" target="_blank">auther</a></figcaption> </figure> <figure><img src="//repo.bfw.wiki/random/400x300/景色?rand=3"/> <figcaption>photo by <a href="" target="_blank">auther</a></figcaption> </figure> <figure><img src="//repo.bfw.wiki/random/400x300/景色?rand=4"/> <figcaption>photo by <a href="" target="_blank">auther</a></figcaption> </figure> <figure><img src="//repo.bfw.wiki/random/400x300/景色?rand=5"/> <figcaption>photo by <a href="" target="_blank">auther</a></figcaption> </figure> <figure><img src="//repo.bfw.wiki/random/400x300/景色?rand=6"/> <figcaption>photo by <a href="" target="_blank">auther</a></figcaption> </figure> <figure>&.........完整代码请登录后点击上方下载按钮下载查看
网友评论0