jQuery中 图像视差/模糊/缩放效果 视差

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

简介

一个全新的jQuery视差插件,它将可配置的平滑视差滚动动画应用于滚动图像,以及模糊和缩放效果。

由CSS3转换和转换提供动力。非常适合展示你的最新作品,或者只是偶尔添加一些页面元素。

参见:

  • 10个最佳视差滚动效果

如何使用它:

1.在加载最新的jQuery库之后加载视差插件。

  1. <!-- Slim build is recommended -->
  2. <script src="/path/to/cdn/jquery.slim.min.js"></script>
  3.  
  4. <!-- jQuery parallax plugin -->
  5. <script src="dist/jquery-parallax.js"></script>

2.将一组绝对定位的图像添加到页面中。

  1. <img src="1.jpg" alt="Parallax Image 1" />
  2. <img src="2.jpg" alt="Parallax Image 2" />
  3. <img src="3.jpg" alt="Parallax Image 3" />
  4. ...
  1. img {
  2. max-width:300px;
  3. display:block;
  4. position:absolute;
  5. top:200px;
  6. left:200px;
  7. }

3.为每个图像配置视差/蓝色/比例效果。

  1. var data = [
  2. {speed:30,blur:3,scale:.8},
  3. {speed:40,index:2},
  4. {speed:30,blur:2,scale:.7},
  5. // ...
  6. ];

4.将视差滚动效果应用于图像。

  1. $('img').each(function(i,o){
  2. $(this).parallax(data[i]);
  3. });

5.所有可能的插件选项。

  1. $("img").parallax({
  2.  
  3. // animation speed in pixels
  4. speed: 30,
  5.  
  6. // or "x"
  7. axis: "Y",
  8.  
  9. // scale factor
  10. scale: 1,
  11.  
  12. // z-index
  13. index: 0,
  14.  
  15. // delay in seconds
  16. delay: 1.4,
  17.  
  18. // blur level
  19. blur: 0,
  20.  
  21. // disable on mobile
  22. mobile: false,
  23.  
  24. });

预览截图