jQuery中 冷却反向滚动(拆分滚动)效果

  • 源码大小:5.71KB
  • 所需积分:1积分
  • 源码编号:19JP-3699
  • 浏览次数:760次
  • 最后更新:2023年07月12日
  • 所属栏目:动画
本站默认解压密码:19jp.com 或 19jp_com

简介

用jQuery和CSS编写的一个非常反向的滚动效果,这意味着用户可以以不同的滚动方向(从上到下和从下到上)滚动多列内容。

请参阅实际操作:

参见:

  • jQuery中的现代拆分旋转木马滑块-Splitt.js
  • jQuery中的交互式分屏动画
  • 带视差效果的全屏拆分卡片滑块-内容滑块

如何使用它:

1.在页面中插入两列或多列内容。

  1. <div class="container-1">
  2. <div class="image">
  3. <img src="1-1.jpg">
  4. </div>
  5. <!-- More Content -->
  6. </div>
  7.  
  8. <div class="container-1">
  9. <div class="image">
  10. <img src="2-1.jpg">
  11. </div>
  12. <!-- More Content -->
  13. </div>
  14.  
  15. <div class="container-1">
  16. <div class="image">
  17. <img src="3-1.jpg">
  18. </div>
  19. <!-- More Content -->
  20. </div>
  1. .container-1 {
  2. display: flex;
  3. flex-direction: column;
  4. align-items: center;
  5. justify-content: space-between;
  6. width: calc(100% / 3);
  7. box-sizing: border-box;
  8. height: 3000px;
  9. }
  10.  
  11. .container-2 {
  12. display: flex;
  13. flex-direction: column;
  14. align-items: center;
  15. justify-content: space-between;
  16. width: calc(100% / 3);
  17. box-sizing: border-box;
  18. position: fixed;
  19. left: calc(100% / 3);
  20. bottom: 0;
  21. height: 3000px;
  22. padding-bottom: 15vh;
  23. }
  24. .container-3 {
  25. display: flex;
  26. flex-direction: column;
  27. align-items: center;
  28. justify-content: space-between;
  29. width: calc(100% / 3);
  30. box-sizing: border-box;
  31. height: 3000px;
  32. }

2.在文档中加载必要的jQuery JavaScript库。

  1. <script src="/path/to/cdn/jquery.slim.min.js"></script>

3.启用第二列上的反向滚动的主脚本。

  1. $(window).on('scroll',function(){
  2. $(".container-2").css('bottom',$(window).scrollTop()*-1);
  3. });

预览截图