10-26-1-flipping-widget-3d-context.html 5.4 KB

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