css实现 scroll-snap滚动吸附效果代码

代码语言:html

所属分类:加载滚动

代码描述:css实现 scroll-snap滚动吸附效果代码

代码标签: css scroll-snap 滚动 吸附

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

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

<head>
    <meta charset="utf-8">
 <style>
     :root {
    --background: #1F2336;
    --scrollbar-background: #313852;
    --text: #F1F1F1;
    --text-active: #F1F1F180;
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: 'Manrope', sans-serif;
    height: 100vh;
    display: flex;
    background-color: var(--background);
    justify-content: center;
    align-items: center;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

.container {
    display: flex;
    flex-direction: row;
    gap: 1.5rem;
    padding: 1rem;
    max-width: 200px;
    overflow-x: scroll;
    scroll-snap-type: x mandatory;
}

.card {
    min-width: 12.5rem;
    min-height: 12.5rem;
    color: var(--text);
    display: flex;
    font-weight: 600;
    font-size: 1.5rem;
    border-radius: 1rem;
    transition: all 0.2s;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    scroll-snap-align: start;
}

.card:nth-child(1) {
    background-image: linear-gradient(to bottom, #9377F2, #6250D7);
}

.card:nth-child(2) {
    background-image: linear-gradient(to bottom, #E5866C, #DF.........完整代码请登录后点击上方下载按钮下载查看

网友评论0