Giter VIP home page Giter VIP logo

knockout.animate's Introduction

knockout.animate

Animate.css custom binding for Knockout.js

animate.css is a bunch of cool, fun, and cross-browser animations for you to use in your projects now with support of Knockout.js. Great for emphasis, home pages, sliders, and general just-add-water-awesomeness.

Installing

Download knockout.animate.min.js and all dependencies (animate.css, knockout.js) or use Bower command:

bower install knockout.animate

Usage

To use knockout.animate in your website, simply drop the animate.css, knockout.js and knockout.animate.js into your document's :

<head>
  <link rel="stylesheet" href="animate.min.css">
  <script type="text/javascript" src="knockout.min.js"></script>
  <script type="text/javascript" src="knockout.animate.min.js"></script>
</head>

Then add next data-binding to an element:

<div data-bind="animate:{ animation: 'zoomIn', state: true"></div>

That's it! You've got a CSS animated element. Super!

Use observable to control animation

You can control when animation is going to happen by assigning Knockout Observable to state field:

<div data-bind="animate:{ animation: 'zoomIn', state: state"></div>
function Viewmodel(){
  this.state = ko.observable(true);
}

ko.applyBindings(new Viewmodel());

Animation will be played when observable become true.

Assign in and out states and toggle between them

You can add in and out animation this way:

<div data-bind="animate:{ animation: ['zoomIn', 'zoomOut'], state: state"></div>

First animation will be played when state field become true and second when false.

Assign custom handlers on state change

The before and after

<div data-bind="animate:{ animation: 'zoomIn', state: state, before: beforeAnimate, after: afterAnimate }, text: message">
  Hello World!
</div>
function Viewmodel(){
  this.state = ko.observable(true);
  this.message = ko.observable('Hello World!');
  
  this.afterAnimate = function(event, state){
    this.message = ko.observable('Goodbye World!');
  }
}

ko.applyBindings(new Viewmodel());

removeClass and animation-fill-mode: forwards

In some cases you may not want to remove the animation class (bounceInRight...) after the animation has finished.

This can be the case when using the CSS property animation-fill-mode: forwards.

In that case you can set the option removeClass to false:

<div data-bind="animate:{ animation: 'zoomIn', state: state, removeClass: false }">
  Hello World!
</div>

The class will then only be removed when state is toggled again.

Reference: https://developer.mozilla.org/en/docs/Web/CSS/animation-fill-mode

knockout.animate's People

Contributors

dnbard avatar malthejorgensen avatar danielormeno avatar

Watchers

David Kofoed Wind avatar James Cloos avatar Paulo Cunha 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.