browserify.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /**
  2. * Transitionize example.
  3. *
  4. * Shows how to change dynamically the transitions of an element.
  5. *
  6. * In this case, the `elem` background color and left properties are given different transition duration,
  7. * according to it's current position. If the circle is in it's initial position, it goes right and
  8. * changes background color faster. If it's already been moved - gets back left and changes background
  9. * color slower.
  10. *
  11. * In order for this to work, with Browserify(http://browserify.org/) already installed, execute the following command:
  12. *
  13. * browserify examples/browserify.js -o examples/bundle.js
  14. *
  15. */
  16. var transitionize = require('../transitionize');
  17. window.onload = function() {
  18. var elem = document.querySelector('.js-elem')
  19. , prop = {};
  20. elem.addEventListener('click', function() {
  21. var position = parseInt(elem.style.left) || 0;
  22. if (position == 0) {
  23. this.style.left = this.parentNode.offsetWidth - this.offsetWidth + 'px';
  24. this.style.backgroundColor = '#53e7d0';
  25. prop = {
  26. 'background-color': '0.3s'
  27. , 'left': '0.3s'
  28. };
  29. } else {
  30. this.style.left = 0;
  31. this.style.backgroundColor = '#febf04';
  32. prop = {
  33. 'background-color': '1s'
  34. , 'left': '1s'
  35. };
  36. }
  37. transitionize(elem, prop);
  38. });
  39. };