UNPKG

tram

Version:

Cross-browser CSS3 transitions in JavaScript

98 lines (84 loc) 2.34 kB
<!doctype html> <html> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <title>tram.js example</title> <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no"> <link rel="stylesheet" href="../support/styles/example.css"> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> <script>window.jQuery || document.write('<script src="../node_modules/jquery/dist/jquery.min.js"><\/script>')</script> <script src="../dist/tram.js"></script> </head> <body> <p> Sequencing demo. Click or tap to change the sequence. </p> <div class="funbox"> <div class="abs test"></div> </div> <script> var $funbox = $('.funbox'); var $test = $('.test'); // define transitions tram($test) .add('background 0.7s ease') .add('width 500ms ease-out-back') .add('height 500ms ease-out-back') .add('transform 300ms ease-out-quint') ; // start first sequence funtime(); // sequences function funtime() { tram($test) .start({ x: 0, y: 0, width: 100, height: 100 }) .then({ x: 50, width: 200 }) .then({ y: 100, height: 200 }) .then({ x: 0, width: 50 }) .then(funtime) ; } function happytime() { tram($test) .start({ x: 100, y: 100, width: 200, height: 200, background: '#FF374E' }) .then({ x: 20 }) .then({ rotate: 90 }) .then({ rotate: 0 }) .then(happytime) ; } function breaktime() { tram($test) .start({ rotate: 0, background: '' }) .then(funtime) ; } function slower() { tram($test) .add('width 1s') .add('height 1s') .add('transform 800ms') ; } function faster() { tram($test) .add('width 500ms') .add('height 500ms') .add('transform 300ms') ; } // click events var touch = 'ontouchstart' in window; var clicks = 0; $funbox.on(touch ? 'touchstart' : 'mousedown', function () { switch (++clicks) { case 1: happytime(); break; case 2: slower(); break; case 3: breaktime(); break; case 4: faster(); clicks = 0; break; } }); </script> </body> </html>