不知道要做甚麼樣式的實作,所以我想做一個像遊戲的實作。
HTML
<div class="container">
<div class="item" onclick="hideItem(this)">Item 1</div>
<div class="item" onclick="hideItem(this)">Item 2</div>
<div class="item" onclick="hideItem(this)">Item 3</div>
<div class="item" onclick="hideItem(this)">Item 4</div>
<div class="item" onclick="hideItem(this)">Item 5</div>
</div>
CSS(Sass)
$item-count: 5
$bg-color: #2c3e50
$item-hover-color: #3498db
@keyframes fadeInOutScale
0%, 100%
opacity: 0
transform: scale(0.8)
50%
opacity: 1
transform: scale(1.2)
.container
display: flex
justify-content: center
align-items: center
height: 100vh
background-color: $bg-color
flex-wrap: wrap
.item
background-color: #fff
padding: 20px
color: #333
font-size: 1.5rem
border-radius: 8px
margin: 10px
animation: fadeInOutScale 3s infinite
transition: background-color 0.3s, transform 0.3s, opacity 0.3s
&:hover
background-color: $item-hover-color
transform: scale(1.1)
&.hidden
display: none
Javascript
let hiddenCount = 0;
function hideItem(element) {
element.classList.add('hidden');
hiddenCount++;
if (hiddenCount === 5) {
setTimeout(() => {
const items = document.querySelectorAll('.item');
items.forEach(item => {
item.classList.remove('hidden');
});
hiddenCount = 0;
}, 2000);
}
}
明天再繼續。
加油!