You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

91 lines
2.3 KiB

  1. /*
  2. * transform: A jQuery cssHooks adding 2D/3D transform capabilities to $.fn.css() and $.fn.animate()
  3. *
  4. * Requirements:
  5. * - jQuery 1.5.1+
  6. * - jquery.transition.js for animations
  7. * - browser implementing W3C's CSS 2DTransforms for 2D tranform
  8. * - browser implementing W3C's CSS 3DTransforms for 3D tranform
  9. *
  10. * latest version and complete README available on Github:
  11. * https://github.com/louisremi/jquery.transform.js
  12. *
  13. * Copyright 2011 @louis_remi
  14. * Licensed under the MIT license.
  15. *
  16. * This saved you an hour of work?
  17. * Send me music http://www.amazon.co.uk/wishlist/HNTU0468LQON
  18. *
  19. */
  20. (function( $, window, document ) {
  21. "use strict";
  22. var div = document.createElement("div"),
  23. divStyle = div.style,
  24. prefixes = [
  25. "O",
  26. "ms",
  27. "Webkit",
  28. "Moz"
  29. ],
  30. prefix,
  31. i = prefixes.length,
  32. properties = [
  33. "transform",
  34. "transformOrigin",
  35. "transformStyle",
  36. "perspective",
  37. "perspectiveOrigin",
  38. "backfaceVisibility"
  39. ],
  40. property,
  41. j = prefixes.length;
  42. // Find the right prefix
  43. while ( i-- ) {
  44. if ( prefixes[i] + leadingUppercase( properties[0] ) in divStyle ) {
  45. prefix = prefixes[i];
  46. continue;
  47. }
  48. }
  49. // This browser is not compatible with transforms
  50. if ( !prefix ) { return; }
  51. // Build cssHooks for each property
  52. while ( j-- ) {
  53. property = prefix + leadingUppercase( properties[j] );
  54. if ( property in divStyle ) {
  55. // px isn't the default unit of this property
  56. $.cssNumber[ properties[j] ] = true;
  57. // populate cssProps
  58. $.cssProps[ properties[j] ] = property;
  59. // MozTranform requires a complete hook because "px" is required in translate
  60. property === "MozTransform" && ($.cssHooks[ properties[j] ] = {
  61. get: function( elem, computed ) {
  62. return (computed ?
  63. // remove "px" from the computed matrix
  64. $.css( elem, property ).split("px").join(""):
  65. elem.style[property]
  66. );
  67. },
  68. set: function( elem, value ) {
  69. // add "px" to matrices
  70. /matrix\([^)p]*\)/.test(value) && (
  71. value = value.replace(/matrix((?:[^,]*,){4})([^,]*),([^)]*)/, "matrix$1$2px,$3px")
  72. );
  73. elem.style[property] = value;
  74. }
  75. });
  76. }
  77. }
  78. function leadingUppercase( word ) {
  79. return word.slice(0,1).toUpperCase() + word.slice(1);
  80. }
  81. })( jQuery, window, document );