项目作者: dwayneparton

项目描述 :
jQuery plugin to makes elements animate on scroll.
高级语言: HTML
项目地址: git://github.com/dwayneparton/jquery.scrollmation.js.git
创建时间: 2013-11-25T16:12:08Z
项目社区:https://github.com/dwayneparton/jquery.scrollmation.js

开源协议:GNU General Public License v3.0

下载


ScrollMation

Javascript plugin to makes elements animate on scroll. View it here: Scrollmation Examples

ScrollMation is designed to help developers animate elements on the scroll. Elements flyin and fade out as the user scrolls down the page. It’s not super glamorous but it’s a start.

How it works

Element Options

  1. $("#element").scrollMation({
  2. action : "fadeIn", // fadeIn,fadeOut,flyIn
  3. scrollPos: height-(height*.1), // When to start the scroll. Distance from the top of screen. height = $( window ).height();
  4. duration: (height-247)*.35, // How long the animation lasts. This is a number of scrolled pixels.
  5. startPos: 600, // Elements initial starting postion, used for flyIn
  6. endPos: 0, // Elements ending postion, used for flyIn
  7. });

Make sure you include jQuery and the Scrollmation plugin on your page.

  1. $(document).ready(function() {
  2. //Create all your animations in a function. You define what you want to animate and how.
  3. function yourAnimations(){
  4. //Animate multiple objects the same way
  5. $(".fadein").scrollMation({action : 'fadeIn',});
  6. //FadeIn Code Example
  7. $("#fadeinCode").scrollMation({action : 'fadeIn',});
  8. //FadeOut Code Example
  9. $("#fadeoutCode").scrollMation({action : 'fadeOut', scrollPos : 250,});
  10. //FadeOut Code Example
  11. $("#flyrightCode").scrollMation({action : 'flyIn', startPos : 600, endPos: 0,});
  12. //FadeOut Code Example
  13. $("#flyleftCode").scrollMation({action : 'flyIn', startPos : -600, endPos: 0,});
  14. //Multiple Code Example
  15. $("#multipleCode").scrollMation({action : 'fadeIn',});
  16. $("#multipleCode").scrollMation({action : 'flyIn', startPos : -600, endPos: 0,});
  17. }
  18. //Initiate the animations so that they apply before the user starts scrolling.
  19. yourAnimations();
  20. //Add the scroll event and call the animations function.
  21. $(window).scroll(function(){
  22. yourAnimations();
  23. });
  24. });

Keep Scrolling for Examples.

Fading In

  1. $(document).ready(function() {
  2. //Create all your animations in a function. You define what you want to animate and how.
  3. function yourAnimations(){
  4. $("#fadeinCode").scrollMation({action : 'fadeIn',});
  5. }
  6. //Initiate the animations so that they apply before the user starts scrolling.
  7. yourAnimations();
  8. //Add the scroll event and call the animations function.
  9. $(window).scroll(function(){
  10. yourAnimations();
  11. });
  12. });

Fade Out

With fadeout you will want to add a higher scroll position.

  1. $(document).ready(function() {
  2. //Create all your animations in a function. You define what you want to animate and how.
  3. function yourAnimations(){
  4. $("#fadeoutCode").scrollMation({action : 'fadeOut', scrollPos : 250,});
  5. }
  6. //Initiate the animations so that they apply before the user starts scrolling.
  7. yourAnimations();
  8. //Add the scroll event and call the animations function.
  9. $(window).scroll(function(){
  10. yourAnimations();
  11. });
  12. });

Fly In

Fly From Right

  1. $(document).ready(function() {
  2. //Create all your animations in a function. You define what you want to animate and how.
  3. function yourAnimations(){
  4. $("#flyrightCode").scrollMation({action : 'fadeIn', startPos : 600, endPos: 0,});
  5. }
  6. //Initiate the animations so that they apply before the user starts scrolling.
  7. yourAnimations();
  8. //Add the scroll event and call the animations function.
  9. $(window).scroll(function(){
  10. yourAnimations();
  11. });
  12. });

Fly From Left

  1. $(document).ready(function() {
  2. //Create all your animations in a function. You define what you want to animate and how.
  3. function yourAnimations(){
  4. $("#flyleftCode").scrollMation({action : 'fadeIn', startPos : -600, endPos: 0,});
  5. }
  6. //Initiate the animations so that they apply before the user starts scrolling.
  7. yourAnimations();
  8. //Add the scroll event and call the animations function.
  9. $(window).scroll(function(){
  10. yourAnimations();
  11. });
  12. });

Multiple Effects

You can add multiple effects to the same element. That’s not really that impressive since there are only 3 effects but you can make a nice fade in slide effect like this:

  1. $(document).ready(function() {
  2. //Create all your animations in a function. You define what you want to animate and how.
  3. function yourAnimations(){
  4. $("#multipleCode").scrollMation({action : 'fadeIn',});
  5. $("#multipleCode").scrollMation({action : 'flyIn', startPos : -600, endPos: 0,});
  6. }
  7. //Initiate the animations so that they apply before the user starts scrolling.
  8. yourAnimations();
  9. //Add the scroll event and call the animations function.
  10. $(window).scroll(function(){
  11. yourAnimations();
  12. });
  13. });

Apply Same Effect to Muliple Objects

You can apply effects to elements of a certain class by defining the class animation:

  1. $(document).ready(function() {
  2. //Create all your animations in a function. You define what you want to animate and how.
  3. function yourAnimations(){
  4. $(".fadein").scrollMation({action : 'fadeIn',});
  5. }
  6. //Initiate the animations so that they apply before the user starts scrolling.
  7. yourAnimations();
  8. //Add the scroll event and call the animations function.
  9. $(window).scroll(function(){
  10. yourAnimations();
  11. });
  12. });

Things Worth Noting

  • You may need to add overflow:hidden; to the container or <body style="overflow-x: hidden;"> in order to prevent the scroll bar from showing. May add this in the future.