10-26-flipping-widget.html 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <!DOCTYPE html>
  2. <html lang="en" class="no-js">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1">
  6. <title>A 3D flipping widget</title>
  7. <!-- Load modernizr first, so that all the class names we base our
  8. styles on are there as early as possible. -->
  9. <script src="js/modernizr.js"></script>
  10. <script>
  11. // The following test is here to detect svg background-image support for the
  12. // checkboxes, and is not specifically related to this example.
  13. Modernizr.addTest('svgbg', document.implementation.hasFeature('http://www.w3.org/TR/SVG11/feature#Image', '1.1'));
  14. </script>
  15. <!-- We'll put styles from the menu example in a separate file and re-use
  16. them for this example. -->
  17. <link rel="stylesheet" href="css/menu.css">
  18. <style>
  19. /**
  20. * 1. Generally, we'd set perspective for all browsers here.
  21. * Since IE is buggy with regards to perspective and requires
  22. * the perspective() function instead, we use that (see below) -
  23. * which doesn't play nice with iOS (sigh). Therefore, we just supply
  24. * the -webkit-perspective property here.
  25. */
  26. .csstransforms3d.classlist .flip-wrapper {
  27. position: relative;
  28. -webkit-perspective: 1000px; /* 1 */
  29. }
  30. /**
  31. * Rules common to the two sides of the widget.
  32. * 1. We set the backface visibility to hidden, so that we don't need to
  33. * worry about the back of the "cards" shining through.
  34. */
  35. .csstransforms3d.classlist .flip-b,
  36. .csstransforms3d.classlist .flip-a {
  37. box-sizing: border-box;
  38. -webkit-transition: -webkit-transform .25s ease-in-out;
  39. -moz-transition: -moz-transform .25s ease-in-out;
  40. transition: transform .25s ease-in-out;
  41. -webkit-backface-visibility: hidden; /* 1 */
  42. -moz-backface-visibility: hidden; /* 1 */
  43. backface-visibility: hidden; /* 1 */
  44. }
  45. .csstransforms3d.classlist .flip-a {
  46. -webkit-transform: perspective(1000px) rotateY(0); /* 1 */
  47. -moz-transform: perspective(1000px) rotateY(0); /* 1 */
  48. transform: perspective(1000px) rotateY(0); /* 1 */
  49. }
  50. /**
  51. * The backside of the widget.
  52. * 1. Set the card to be absolutely positioned inside the parent, and
  53. * set the top/right/bottom/left props to 0 so that the element stretches
  54. * to fill the entire space of the parent (now equal to the space of side A!).
  55. * 2. Remove any margin.
  56. * 3. Set the perspective and flip the card -180 degrees, so it ends up
  57. * "behind" side A.
  58. */
  59. .csstransforms3d.classlist .flip-b {
  60. position: absolute; /* 1 */
  61. top: 0;
  62. left: 0;
  63. right: 0;
  64. bottom: 0;
  65. margin: 0; /* 2 */
  66. -webkit-transform: perspective(1000px) rotateY(-180deg); /* 3 */
  67. -moz-transform: perspective(1000px) rotateY(-180deg); /* 3 */
  68. transform: perspective(1000px) rotateY(-180deg); /* 3 */
  69. }
  70. /**
  71. * 1. When the parent has the class indicating flipped state, rotate side A
  72. * 180 degrees.
  73. */
  74. .csstransforms3d.classlist .flip-wrapper.is-flipped .flip-a {
  75. -webkit-transform: perspective(1000px) rotateY(180deg); /* 1 */
  76. -moz-transform: perspective(1000px) rotateY(180deg); /* 1 */
  77. transform: perspective(1000px) rotateY(180deg); /* 1 */
  78. }
  79. /**
  80. * 1. When the parent has the class indicating flipped state, rotate side B
  81. * back to 0 degrees.
  82. */
  83. .csstransforms3d.classlist .flip-wrapper.is-flipped .flip-b {
  84. -webkit-transform: perspective(1000px) rotateY(0deg); /* 1 */
  85. -moz-transform: perspective(1000px) rotateY(0deg); /* 1 */
  86. transform: perspective(1000px) rotateY(0deg); /* 1 */
  87. }
  88. /**
  89. * These two classes are used by the JS to toggle the visibility property
  90. * in order to prevent the user from tabbing into the side that is hidden.
  91. * These classes are added/removed in conjunction with the transition-events
  92. * that are emitted when the widget has rotated - see the JS file if you
  93. * want to dig deeper!
  94. */
  95. .csstransforms3d.classlist .flip-enabled {
  96. visibility: visible;
  97. }
  98. .csstransforms3d.classlist .flip-disabled {
  99. visibility: hidden;
  100. }
  101. </style>
  102. </head>
  103. <body>
  104. <div class="flip-wrapper menu-wrapper">
  105. <div class="flip-a menu">
  106. <h1 class="menu-heading">Top menu choices</h1>
  107. <ol class="menu-list">
  108. <li>Capricciosa</li>
  109. <li>Margherita</li>
  110. <li>Vesuvio</li>
  111. <li>Calzone</li>
  112. <li>Quattro Stagioni</li>
  113. <li>Pescatore</li>
  114. <li>Bolognese</li>
  115. <li>Shawarma</li>
  116. <li>Mexicana</li>
  117. <li>Fungi</li>
  118. </ol>
  119. </div>
  120. <div class="flip-b menu-settings">
  121. <form action="">
  122. <h2>Show only these pizzas:</h2>
  123. <ul class="checkboxes">
  124. <li>
  125. <input type="checkbox" checked name="meat" id="checkbox-meat">
  126. <label for="checkbox-meat">Pizzas with meat</label>
  127. </li>
  128. <li>
  129. <input type="checkbox" checked name="fish" id="checkbox-fish">
  130. <label for="checkbox-fish">Pizzas with fish or seafood</label>
  131. </li>
  132. <li>
  133. <input type="checkbox" checked name="veg" id="checkbox-veg">
  134. <label for="checkbox-veg">Vegetarian pizzas</label>
  135. </li>
  136. </ul>
  137. <!-- The button for filtering pizzas can presumably be included in
  138. the markup, since it could potentially be -->
  139. <button type="submit" class="menu-save">Show me pizzas!</button>
  140. </form>
  141. </div>
  142. </div>
  143. <p><a href="#">Focusable link</a></p>
  144. <!-- Here, we link to the JS file powering the flippable widget. -->
  145. <script src="js/flipwidget.js"></script>
  146. <script>
  147. // Initialize the flip widget with options:
  148. window.FlipWidget({'flipElementSel': '.flip-a'});
  149. </script>
  150. </body>
  151. </html>