cardSpreadPosition实现滚动卡片堆叠位移动画效果代码

代码语言:html

所属分类:加载滚动

代码描述:cardSpreadPosition实现滚动卡片堆叠位移动画效果代码,结合了scroll-timeline.js插件。

代码标签: cardSpreadPosition 滚动 卡片 堆叠 位移 动画

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  

  
  
<style>
@import url("https://fonts.googleapis.com/css2?family=Asap&display=swap");
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}
*::before,
*::after {
    box-sizing: border-box;
}
html,
body {
    overscroll-behavior-x: none;
    overscroll-behavior-y: none;
    scroll-behavior: smooth;
}
body {
    font-family: "Asap", sans-serif;
    position: relative;
    width: 100%;
    min-height: 100vh;
    text-align: center;
    overflow-x: clip;
    color: gray;
    display: grid;
    place-items: center;
}
body::before {
    content: "";
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    background: linear-gradient(
        135deg,
        rgba(222, 191, 244, 1) 0%,
        rgba(255, 178, 178, 1) 100%
    );
}
main {
    width: 100%;
    max-width: 100vw;
    display: grid;
    place-items: center;
}

#gallery {
    --size: 200px;
    --gap: 10px;
    --space: 10px;

    position: relative;
    width: min(100%, 1000px);
    overflow-x: visible;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(var(--size), 1fr));
    gap: var(--gap);
    padding: var(--gap);

    transform: translateZ(0);
    -webkit-backface-visibility: hidden;
            backface-visibility: hidden;
}
@media (max-width: 500px) {
    #gallery {
        --size: 170px;
    }
}
@property --card-angle {
    syntax: "<angle>";
    initial-value: 0deg;
    inherits: false;
}
@property --card-x {
    syntax: "<length>";
    initial-value: 0px;
    inherits: false;
}
@property --card-y {
    syntax: "<length>";
    initial-value: 0px;
    inherits: false;
}
.card {
    --img: url();
    --card-x: 0px;
    --card-y: 0px;
    --card-angle: 0deg;

    /* sticky! */
    position: sticky;
    bottom: calc(var(--size) * -1.15);

    display: grid;
    place-items: center;

    width: 100%;
    aspect-ratio: 1 / 1.25;
    padding: 0.5rem;

    background-color: floralwhite;
    border-radius: 10px;
    filter: drop-shadow(0.3rem 0.3rem 0.3rem rgba(0, 0, 0, 0.5));

    -webkit-animation: anim linear both;

            animation: anim linear both;
    animation-timeline: view();
    animation-ran.........完整代码请登录后点击上方下载按钮下载查看

网友评论0