Code Monkey home page Code Monkey logo

charlie.js's Introduction

charlie.js

A small framework for synchronizing video and CSS3 animations.

You can see a live demo here (watch on a laptop/desktop and give it at least 30 seconds to really see how it works): http://www.sketchingwithcss.com/flexbox/

Create your CSS3 animations with the naming convention

The animation properties should be defined with a class selector that matches the name of the corresponding keyframe.

.grow {
	animation-name: grow;
	animation-duration: 4s;
	animation-timing-function: linear;
	animation-iteration-count: 1;
	animation-direction: normal;
    animation-fill-mode: forwards;
}

@keyframes grow {
   0% {
       width: 5px;
       height: 5px;
   }

   100% {
       width: 50px;
       height: 50px;
   }
}

Notice the class name matches the animation-name matches the keyframes name.

Add the "charlie" class, data-animations and data-times

In your markup add a 'charlie' class to any element that you will animate. Then add two data attributes: data-animations and data-times.

  • data-animations - A comma separated list of the animation names that will run on this element. The names should be the same as the class/keyframe combo in your stylesheet.

  • data-times - A comma separated list of times when the animations will run. These times are synced with the video. There must be one time for every animation. Times are in seconds with a resolution to a tenth of a second.

e.g.

<div class="charlie" data-animations="grow, shrink" data-times="40.2, 90.3">
</div>

Include the right javascript

Within the demo directory of this project is a charlie.js which contains charlie.js plus all of its dependencies. You can use this version if you want. Or you can include charlie.js and it's dependencies individually.

You must include underscore.js and the polyfills.js file in this repository.

Make the CHARLIE.setup(video) call

Somewhere in your javascript get a reference to the video element you will sync with the animations. Then call CHARLIE.setup.

CHARLIE.setup(video);

Include Javascript callbacks with CHARLIE.addCallback

For fancier and more complicated use cases you will need more than just CSS3 animations. There will be other state on your page you need to maintain, so you can add Javascript callbacks at arbitrary times.

CHARLIE.addCallback(function(){
    // do stuff in here
}, 43.2);

Charlie.js does a pretty good job of maintaining animation state and keeping everything in sync as you jump around a video, but this is not the case with your Javascript callbacks.

As of now, if you add a bunch of callbacks that affect the state of the page, you will have to manually handle keeping the state in sync if a user starts jumping around in the video.

So you will need to add event listeners to the video by hand. Eventually, Charlie.js might add some better mechanisms to help, but you're on your own for now.

Gotchas

  • There is a bug in Chrome where the cssRules property on a stylesheet is null if you load the stylesheet using the file: protocol. So you'll have to serve up the demo, you can't just open the file.

  • Does not respond to framerate changes. So if the video stutters or you want to slow down the rate of the video, the animations will be out of sync.

charlie.js's People

Contributors

sfioritto avatar

Stargazers

Jeffrey Xavier avatar Michael Barley avatar Ξunit avatar Howard Chiam avatar Musaib avatar Florian Wetschoreck avatar Sandra Dumas avatar James George avatar Akash avatar bindy avatar Justin Bennett avatar Jose Fernandez avatar htmlstrap avatar Jordan White avatar Srijan Shukla avatar Benjamin Spak avatar Casper Juel avatar Pascal Boucher avatar Mathieu M-Gosselin avatar Dan Gayle avatar Rohitt Vashishtha avatar Neethu Mariya Joy avatar Merzak Seven avatar  avatar LeoTM avatar Lee Sheppard avatar  avatar David Myers avatar Nicolas Copia avatar Naman  avatar Mathew Tyler avatar Lenny Castaneda avatar Alexey Tseitlin avatar Dima Beglov avatar Michael Sheedy avatar RYeah Sh avatar Emmanuel Salomon avatar Cesidio Di Benedetto avatar Matthew Villwock avatar David Mandel avatar Manfredi Giordano avatar Alejandro Mendez avatar Masud Zaman avatar Francis Onwumere avatar Chun-wei Kuo avatar Conail Stewart avatar  avatar Tuan Manh Ha avatar Andrey Andronov avatar Andrew Horst avatar Jacopo Parvizi avatar Daniel Bayley avatar Quiz Chu avatar Frederik De Bleser avatar Pedro Simão avatar Chris Witko avatar Michael Hulse avatar Thiru avatar Kyle King avatar Johan Bové avatar Casey Weed avatar Vladimir Stegantsov avatar Dinh Nguyen avatar Chris Boden avatar Azi Essance avatar Adam Henley avatar Jiří Matoušek avatar Piotr Jan Sikora avatar Michael Anthony avatar Adnan Khan avatar Stuart Zahn avatar  avatar Mladen Krivaćević avatar Eirik L. Vullum avatar Albert Abril avatar Brannon Lucas avatar Manikanta Gade avatar Robert Evans avatar Chris Weight avatar Daniel Lohse avatar Gokce Ozan Toptas avatar detra avatar Nathan Gathright avatar Ryan Hightower avatar Drew Jagdat avatar Trever Yarrish avatar Barry Clark avatar George Bullock avatar Elon Zito avatar Código y Arte avatar Bruno Melo avatar Juan Jorquera avatar Salahuddin Hairai avatar Sean Goresht avatar Adam Shaylor avatar Brian Cameron avatar Jason DeLosSantos avatar Andrew Abogado avatar Stephen McKamey avatar Viktor Vasilev avatar

Watchers

Dirk Sidney Jansen avatar Brad Jones avatar Sindri Bergmann avatar  avatar Juan Cabrera avatar Andrew Gaerig avatar Mikhaël Aubut avatar Wayne Patterson avatar James Cloos avatar  avatar Brian Kelley avatar Vinoth Shankaran avatar Michael Anthony avatar Jamison Rea avatar Peter Rosellen avatar mori avatar  avatar Dylan George avatar  avatar Cedric Jud avatar Lenny Castaneda avatar Kurt Calloway avatar Jose Fernandez 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.