• css 滚动贴合


    大部分人基本上都会使用JS实现页面的滚动贴合效果,在学习的过程中,偶然发现原生CSS实现滚动贴合效果的方法;

    html 代码

    1. html>
    2. <html lang="en">
    3. <head>
    4. <meta charset="UTF-8">
    5. <title>滚动贴合title>
    6. <style>
    7. * {
    8. margin: 0;
    9. padding: 0;
    10. }
    11. .container {
    12. width: 1200px;
    13. height: 100vh;
    14. overflow-y: scroll;
    15. scroll-snap-type: y mandatory;
    16. margin: auto;
    17. }
    18. .container .item {
    19. width: 100%;
    20. height: 100%;
    21. padding: 30px;
    22. border: 1px dashed #cccccc;
    23. box-sizing: border-box;
    24. scroll-snap-align: start;
    25. border-radius: 10px;
    26. background: #f9f9f9;
    27. margin-bottom: 16px;
    28. }
    29. .container .item:last-child {
    30. margin-bottom: 0;
    31. }
    32. .container .item img {
    33. width: 100%;
    34. height: 100%;
    35. object-fit: cover;
    36. border: 1px solid #ffffff;
    37. transition: all 0.4s;
    38. }
    39. .container .item:hover img {
    40. box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
    41. border-radius: 10px;
    42. }
    43. style>
    44. head>
    45. <body>
    46. <div class="container">
    47. <div class="item">
    48. <img src="https://t7.baidu.com/it/u=4162611394,4275913936&fm=193&f=GIF" alt="">
    49. div>
    50. <div class="item">
    51. <img src="https://t7.baidu.com/it/u=949373678,2089110629&fm=193&f=GIF" alt="">
    52. div>
    53. <div class="item">
    54. <img src="https://t7.baidu.com/it/u=2196842896,2809445370&fm=193&f=GIF" alt="">
    55. div>
    56. <div class="item">
    57. <img src="https://t7.baidu.com/it/u=3779521506,3594871140&fm=193&f=GIF" alt="">
    58. div>
    59. <div class="item">
    60. <img src="https://t7.baidu.com/it/u=3360446468,3126444958&fm=193&f=GIF" alt="">
    61. div>
    62. <div class="item">
    63. <img src="https://t7.baidu.com/it/u=2749005241,3756993511&fm=193&f=GIF" alt="">
    64. div>
    65. <div class="item">
    66. <img src="https://t7.baidu.com/it/u=2928560209,826823219&fm=193&f=GIF" alt="">
    67. div>
    68. <div class="item">
    69. <img src="https://t7.baidu.com/it/u=3780014697,4013718301&fm=193&f=GIF" alt="">
    70. div>
    71. <div class="item">
    72. <img src="https://t7.baidu.com/it/u=832449998,3859178369&fm=193&f=GIF" alt="">
    73. div>
    74. <div class="item">
    75. <img src="https://t7.baidu.com/it/u=1710836566,438775692&fm=193&f=GIF" alt="">
    76. div>
    77. div>
    78. body>
    79. html>

  • 相关阅读:
    AIGC创作系统ChatGPT网站系统源码,支持最新GPT-4-Turbo模型
    Redis缓存同步1-策略介绍
    【一】1D测量 Measuring——measure_projection()算子
    基于深度神经网络的分类--实现与方法说明
    SpringBoot简介
    【leetcode】【初级算法】【链表3】反转链表
    SpringCloud(二)
    VUE+Nodejs 商城项目练习项目(Node部分)
    基于机器视觉的移动消防机器人(一)--功能设计
    springboot(ssm邮件过滤系统 在线邮箱平台Java(code&LW)
  • 原文地址:https://blog.csdn.net/qq_35350009/article/details/133694693