51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

手机号码,快捷登录

查看: 2034|回复: 0
打印 上一主题 下一主题

[原创] stellar视差插件

[复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 2019-1-29 15:51:31 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
视差滚动指网页滚动过程中,多层次的元素进行不同程度的移动,视觉上形成立体运动效果的网页展示技术。主要核心就是前景和背景以不同速度移动,从而创造出3D效果。利用background-attachment属性实现。stellar.js是一个jQuery插件,能很容易地给网站添加视差滚动效果。以下介绍stellar的简单使用:

1.引入js包
  1. <script src="path/to/jquery/jquery.min.js"></script>
  2. <script src="path/to/jquery.stellar.min.js"></script>
复制代码

2.引用HTML和css样式
  1. <div class="content" id="content1">
  2.     <p>TEXT HERE</p>
  3. </div>
  4. <div class="content" id="content2">
  5.     <p>TEXT HERE</p>
  6. </div>
  7. <div class="content" id="content3" data-stellar-background-ratio="0.5">
  8.     <p>TEXT HERE</p>
  9. </div>
  10. <div class="content" id="content4" data-stellar-background-ratio="0.5">
  11.     <p>TEXT HERE</p>
  12. </div>
  13. <div class="content" id="content5" data-stellar-background-ratio="0.5">
  14.     <p>TEXT HERE</p>
  15. </div>
  16. <div class="content" id="content6" data-stellar-background-ratio="0.5">
  17.     <p>TEXT HERE</p>
  18. </div>
  19. //css样式中设置content背景等
复制代码

3.js 调用函数
  1. $.stellar({
  2.     horizontalScrolling: false,
  3.     responsive: true
  4. });
复制代码


4.详细参数


5.实例
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <title>Document</title>
  6.     <style type="text/css">
  7.         html,body{
  8.             height: 100%;
  9.         }
  10.         .content{
  11.             width: 100%;
  12.             height: 100%;
  13.         }
  14.         .content2{
  15.             background: url(images/2.jpg) 0 0/100% 100% no-repeat;
  16.             /*背景图像相对于窗体固定*/
  17.             background-attachment: fixed;
  18.         }
  19.         .content4{
  20.             background: url(images/4.jpg) 0 0/100% 100% no-repeat;
  21.             background-attachment: fixed;
  22.         }
  23.         /*.yezi{
  24.             position: fixed;
  25.             top: 50px;
  26.             right: 10px;
  27.         }*/
  28.     </style>
  29. </head>
  30. <body>
  31.     <!-- data-stellar-ratio 元素针对页面滚动的速度比率 -->
  32.     <!-- <img src="images/big-01.png" alt="" class="yezi" data-stellar-ratio="2"> -->
  33.     <div class="content content1">111</div>
  34.     <!-- data-stellar-background-ratio 设置元素背景的滚动速率 -->
  35.     <div class="content content2" data-stellar-background-ratio="5"></div>
  36.     <div class="content content3">333</div>
  37.     <div class="content content4" data-stellar-background-ratio="0.5"></div>

  38.     <script type="text/javascript" src="jquery.min.js"></script>
  39.     <!-- 引入视差滚动插件stellar -->
  40.     <script type="text/javascript" src="jquery.stellar.min.js"></script>
  41.     <script type="text/javascript">
  42.         $(function(){
  43.             $.stellar({
  44.                 // 设置视差效果方向
  45.                 horizontalScrolling:false,
  46.                 // load或者resize事件触发时是否刷新页面
  47.                 responsive:true
  48.             })
  49.         })
  50.     </script>
  51. </body>
  52. </html>
复制代码



本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?(注-册)加入51Testing

x
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏
回复

使用道具 举报

本版积分规则

关闭

站长推荐上一条 /1 下一条

小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

GMT+8, 2024-9-20 17:52 , Processed in 0.063057 second(s), 24 queries .

Powered by Discuz! X3.2

© 2001-2024 Comsenz Inc.

快速回复 返回顶部 返回列表