页面滚动元素动画效果jQuery插件

当前位置:主页 > jQuery库 > 布局和界面 > 页面滚动元素动画效果jQuery插件
页面滚动元素动画效果jQuery插件
分享:

    插件介绍

    jquery.scrollfx是一款可以制作页面滚动元素动画效果的jQuery插件。通过该插件,用户在滚动页面的时候,可以改变文字的大小以及背景颜色的透明度等,制作出很酷的效果。

    浏览器兼容性

    浏览器兼容性
    时间:04-18
    阅读:
简要教程

jquery.scrollfx是一款可以制作页面滚动元素动画效果的jQuery插件。通过该插件,用户在滚动页面的时候,可以改变文字的大小以及背景颜色的透明度等,制作出很酷的效果。

安装

可以通过npm来安装该插件。

npm install jquery.scrollfx --save                  
                

使用方法

使用该插件需要在页面中引入jquery和jquery.scrollfx.js文件。

<script src="js/jquery.min.js"></script>
<script src="js/jquery.scrollfx.js"></script>                 
                
HTML结构

可以使用<div><section>作为分段容器,里面放置内容。

<section id="first" class="container-fluid">
  <div class="image"></div>
  <div class="container">
    <div class="row">
      <div class="col-md-6 col-md-offset-6">
        <h2>First section with an animation</h2>
        <hr>
        <p class="lead">
          Scroll down to see these texts scale down and see the background change it's opacity.
        </p>
        <a href="#top" class="btn btn-lg btn-primary" data-to-top>
          Scroll to top
          <i class="fa fa-chevron-top"></i>
        </a>
      </div>
    </div>
  </div>
</section>

<section id="second" class="container-fluid">
  <div class="image"></div>
  <div class="container">
    <div class="row">
      <div class="col-md-6">
        <h2>Second section with an animation</h2>
        <hr>
        <p class="lead">
          Scroll down to see these texts scale down and see the background change it's opacity.
        </p>
        <a href="#top" class="btn btn-lg btn-primary" data-to-top>Scroll to top</a>
      </div>
    </div>
  </div>
</section>
......
                
初始化插件

在页面DOM元素加载完毕之后,可以通过scrollFx()方法来初始化该插件。

$(selector).scrollFx(function() {
  scaleElements:    '',   // required
  opacityElements:  '',   // required
  precision:        ''    // optional
});                
                

配置参数

  • scaleElements:类型:String,默认值:''。在页面滚动时被缩放的元素,可以使用“,”来分隔多个元素。
  • opacityElements:类型:String,默认值:''。在页面滚动时被修改透明度的元素,可以使用“,”来分隔多个元素。
  • precision:类型:integer,默认值:10。该参数用于调整性能。该参数值越大,动画越平滑,但是GPU 或 CPU的消耗页越大。

jquery.scrollfx插件的github地址为:https://github.com/marksten/jquery.scrollfx