Guest User

Untitled

a guest
Sep 18th, 2025
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.33 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Card Stacks</title>
  6. <style>
  7. body {
  8. background-color: #0b3d91;
  9. color: white;
  10. font-family: Arial, sans-serif;
  11. text-align: center;
  12. margin: 0;
  13. padding: 30px;
  14. }
  15.  
  16. #shuffleBtn {
  17. margin-bottom: 50px;
  18. padding: 15px 30px;
  19. font-size: 18px;
  20. background-color: #ffcc00;
  21. border: none;
  22. border-radius: 8px;
  23. cursor: pointer;
  24. }
  25.  
  26. .table {
  27. display: flex;
  28. justify-content: center;
  29. gap: 80px;
  30. perspective: 1000px;
  31. }
  32.  
  33. .stack {
  34. display: flex;
  35. flex-direction: column;
  36. gap: 10px;
  37. cursor: pointer;
  38. transition: transform 0.3s;
  39. }
  40.  
  41. .foreground {
  42. transform: scale(1.2);
  43. z-index: 2;
  44. }
  45.  
  46. .background {
  47. transform: translateZ(-100px) scale(0.9);
  48. opacity: 0.8;
  49. z-index: 1;
  50. }
  51.  
  52. .card {
  53. width: 100px;
  54. height: 140px;
  55. background-color: white;
  56. border: 2px solid #333;
  57. border-radius: 8px;
  58. background-image: url('https://upload.wikimedia.org/wikipedia/commons/thumb/5/54/Card_back_06.svg/200px-Card_back_06.svg.png');
  59. background-size: cover;
  60. transition: transform 0.5s;
  61. }
  62.  
  63. .card.face-up {
  64. background-image: none;
  65. background-color: white;
  66. display: flex;
  67. align-items: center;
  68. justify-content: center;
  69. font-size: 30px;
  70. font-weight: bold;
  71. }
  72.  
  73. .black { color: black; }
  74. .red { color: red; }
  75. </style>
  76. </head>
  77. <body>
  78.  
  79. <button id="shuffleBtn">Shuffle Stacks</button>
  80.  
  81. <div class="table" id="table">
  82. <!-- Stacks inserted here by JavaScript -->
  83. </div>
  84.  
  85. <script>
  86. const cardData = [
  87. ['Kâ™ ', 'Kâ™ '],
  88. ['K♠', 'Q♥'],
  89. ['Q♥', 'Q♥']
  90. ];
  91.  
  92. let table = document.getElementById('table');
  93. let states = [0, 0, 0]; // 0 = all down, 1 = top up, 2 = both up
  94.  
  95. function createCard(face) {
  96. const div = document.createElement('div');
  97. div.className = 'card';
  98. div.dataset.face = face;
  99. return div;
  100. }
  101.  
  102. function setCardFace(card, faceUp) {
  103. if (faceUp) {
  104. card.classList.add('face-up');
  105. card.textContent = card.dataset.face;
  106.  
  107. if (card.dataset.face.includes('♥')) {
  108. card.classList.remove('black');
  109. card.classList.add('red');
  110. } else {
  111. card.classList.remove('red');
  112. card.classList.add('black');
  113. }
  114.  
  115. card.style.backgroundImage = 'none';
  116. } else {
  117. card.classList.remove('face-up', 'red', 'black');
  118. card.textContent = '';
  119. card.style.backgroundImage = 'url("https://upload.wikimedia.org/wikipedia/commons/thumb/5/54/Card_back_06.svg/200px-Card_back_06.svg.png")';
  120. }
  121. }
  122.  
  123. function renderStacks(order) {
  124. table.innerHTML = '';
  125. order.forEach((index, pos) => {
  126. const stackDiv = document.createElement('div');
  127. stackDiv.className = 'stack';
  128. stackDiv.classList.add(pos === 1 ? 'foreground' : 'background');
  129. stackDiv.dataset.index = index;
  130.  
  131. const topCard = createCard(cardData[index][0]);
  132. const bottomCard = createCard(cardData[index][1]);
  133. stackDiv.appendChild(topCard);
  134. stackDiv.appendChild(bottomCard);
  135.  
  136. stackDiv.addEventListener('click', () => handleClick(stackDiv));
  137. table.appendChild(stackDiv);
  138. });
  139. }
  140.  
  141. function handleClick(stackDiv) {
  142. const index = +stackDiv.dataset.index;
  143. const cards = stackDiv.querySelectorAll('.card');
  144.  
  145. states[index] = (states[index] + 1) % 3;
  146.  
  147. if (states[index] === 0) {
  148. cards.forEach(card => setCardFace(card, false));
  149. } else if (states[index] === 1) {
  150. setCardFace(cards[0], true);
  151. setCardFace(cards[1], false);
  152. } else if (states[index] === 2) {
  153. cards.forEach(card => setCardFace(card, true));
  154. }
  155. }
  156.  
  157. function shuffleStacks() {
  158. const newOrder = [0, 1, 2].sort(() => Math.random() - 0.5);
  159. renderStacks(newOrder);
  160. }
  161.  
  162. document.getElementById('shuffleBtn').addEventListener('click', shuffleStacks);
  163.  
  164. // Initial render
  165. renderStacks([0, 1, 2]);
  166. </script>
  167.  
  168. </body>
  169. </html>
Advertisement
Add Comment
Please, Sign In to add comment