写一个刮刮乐html页面
时间: 2023-10-24 12:09:50 浏览: 146
好的,这是一个简单的刮刮乐html页面示例:
```html
<!DOCTYPE html>
<html>
<head>
<title>刮刮乐</title>
<style>
#container {
position: relative;
width: 300px;
height: 200px;
background: url(background.jpg);
background-size: cover;
margin: 0 auto;
}
#scratch {
position: absolute;
top: 0;
left: 0;
width: 300px;
height: 200px;
background: #ccc;
font-size: 20px;
font-weight: bold;
line-height: 200px;
text-align: center;
cursor: pointer;
}
#message {
display: none;
position: absolute;
top: 0;
left: 0;
width: 300px;
height: 200px;
background: url(prize.jpg);
background-size: cover;
font-size: 20px;
font-weight: bold;
line-height: 200px;
text-align: center;
}
</style>
</head>
<body>
<div id="container">
<div id="scratch">刮一刮</div>
<div id="message">恭喜你获得一等奖!</div>
</div>
<script>
var scratch = document.getElementById("scratch");
var message = document.getElementById("message");
function revealMessage() {
scratch.style.display = "none";
message.style.display = "block";
}
scratch.addEventListener("mousedown", function() {
revealMessage();
});
</script>
</body>
</html>
```
其中,`background.jpg`为刮刮乐的底图,`prize.jpg`为中奖后显示的图片。用户点击“刮一刮”按钮后,会触发`revealMessage()`函数,使中奖信息显示出来。
阅读全文