Coder Social home page Coder Social logo

wad2eq / force-js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from gravmatt/force-js

0.0 2.0 0.0 41 KB

The easy way to scroll and animate your page

Home Page: http://www.gravmatt.com/force-js/

License: MIT License

JavaScript 66.56% HTML 23.48% CSS 9.96%

force-js's Introduction

Force.js

Finally, an easy way to animate elements and jump around on your page.

It has different easing functions (listed below) and tries (by default) to use CSS-Transitions to animate elements.

If the browser doesn't support transitions, force.js fallback to native javascript functions.

Force.js support even older browser version with no transition support.

See the Demo!

To use it on your page, just write this line of code in the HTML HEAD or on the bottom of the BODY tag.

<script src="force.js" type="text/javascript"></script>

Support for AMD and Node Module Pattern (Including browserify)

Get it on Bower

bower install force-js

jQuery

Force.js is 100% pure vanilla!!!

But for all the coders who don't want to miss jQuery.

Force.js automatically detects jQuery and extend its Objects with the force.move() and force.jump() function.

So you are able to use force.js in an jQuery object.

$('#ball').move({left: 100px, top: 50px}, 1000);

To use force.js in jQuery, write the jQuery TAG first. So force.js can extend its objects afterwards.

Jump

Doing jumps on the page are easier than every.

To automatically detect hash links on your page, just use the force.bindHashes() function like this.

force.bindHashes();

But if you want to do it by yourself, use the force.jump() function.

var element = document.getElementBy('element-id');

// jump by object
force.jump(element);

// jump by selector
force.jump('#element-id');

You can use the function with additional options.

force.jump(target);

var options = {
  setHash: false
  // if set to TRUE, it sets the hash/id value of the element in the URL

  duration: 500,
  done: function() {},
  easing: 'easeInQuad',
};
force.jump(target, options);

Or the jQuery extention.

$('#ball').jump();

//$('#ball').jump(options);

Move

You can also animate elements with force.js.

To do so, just use the force.move() function.

var element = document.getElementBy('element-id');

// jump by object
force.move(element, {left: 100px, top: 50px}, 1000);

// jump by selector
force.move('#element-id', {left: 100px, top: 50px}, 1000);

You can use the function with additional options.

force.move(target, properties, duration, doneCallback);

var options = {
  properties: {
    left: '100px'
  },
  duration: 500,
  done: function() {},
  easing: 'easeInQuad'
};
force.move(target, options);

Or the jQuery extention.

$('#ball').move({left: 100px, top: 50px}, 1000);

// $('#ball').move(options, duration, doneCallback);

Don't worry if you use the function multiple times.

The force.move() function is cached!

That means, the function just get executed if the previous call is done.

Options

In force.js you are able to modify everything you want to fit your needs.

// edit single option
force.opt.cacheScrolling = true;

// or use the config function and paste an object to override the old settings.
force.config( { cacheScrolling: true } );

hashLinkPattern: 'a[href*="#"]:not([href="#"])'

This is a selector to find the hash links in your page by exectuting the force.bindHashes() function.

frames: 60

By default, force.js runs at 60 fps.

You can edit this property as well.

But be careful!

You can increase but also decrease the performance of the page.

moveDuration: 1000 AND jumpDuration: 1000

The default duration for the force.move() and force.jump() function is 1000 ms. You can override this value inside the functions by set the duration property in the config object if you want to.

moveEasing: 'swing' AND jumpEasing: 'swing'

The default easing function is swing but you can change this to:

  • swing
  • easeInQuad
  • easeOutQuad
  • easeInOutQuad
  • easeInCubic
  • easeOutCubic
  • easeInOutCubic
  • easeInQuart
  • easeOutQuart
  • easeInOutQuart
  • easeInQuint
  • easeOutQuint
  • easeInOutQuint
  • easeInSine
  • easeOutSine
  • easeInOutSine
  • easeInExpo
  • easeOutExpo
  • easeInOutExpo
  • easeInCirc
  • easeOutCirc
  • easeInOutCirc
  • easeInElastic*
  • easeOutElastic*
  • easeInOutElastic*
  • easeInBack*
  • easeOutBack*
  • easeInOutBack*
  • easeInBounce*
  • easeOutBounce*
  • easeInOutBounce*

* This easing functions doesn't work with css transitions and use native javascript. But don't worry, force.js does it automatically for you!

cacheJumps: true

Page jumps are cached by default.

That means, the next jump only animates if the previous is finished.

Set it to FALSE and the jump stops immediately and starts the new jump.

cssTransitions: true

By default, force.js try to use css transitions if the browser supports it.

Using transitions looks much smoother than native javascript and doesn't block the event loop.

I would recommend it to let it turned ON by default.

force.js manage the usage of transitions automatically if the browser doesn't support it.

Licence

Force.js is published under the MIT licence. So feel free to use, share or modify it!

force-js's People

Contributors

gravmatt avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.