UNPKG

tram

Version:

Cross-browser CSS3 transitions in JavaScript

65 lines (57 loc) 1.75 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> Basic example of an opacity fade. Hover or tap the boxes. </p> <div class="row"> <div class="test wide"></div> <div class="test wide"></div> </div> <div class="row"> <div class="test wide"></div> <div class="test wide"></div> </div> <div class="row"> <div class="test wide"></div> <div class="test wide"></div> </div> <script> var $el = $('.test'); // intro fade in + callback tram($el) .add('opacity 1s ease-in-out') .set({ opacity: 0 }) .start({ opacity: 1 }) .then(function () { console.log('done!'); }); // element on / off events function toggle(instance, opt, state) { instance .add('opacity ' + opt) .start({ opacity: state ? 0.2 : 1 }); } var touch = 'ontouchstart' in window; $el.each(function (i, el) { var instance = tram(el); $(el).on(touch ? 'touchstart' : 'mouseover', function () { toggle(instance, '0 ease-out-quint', true); }); $(el).on(touch ? 'touchend' : 'mouseout', function () { toggle(instance, '800 ease-in-out', false); }); }); </script> </body> </html>