抽奖jQuery特效代码通常用于网页上的互动活动,通过动画效果增加用户的参与感和乐趣。以下是一个简单的抽奖jQuery特效代码示例:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>抽奖特效</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="lottery-container">
<button id="start-button">开始抽奖</button>
<div id="lottery-wheel">
<div class="lottery-item">奖品1</div>
<div class="lottery-item">奖品2</div>
<div class="lottery-item">奖品3</div>
<div class="lottery-item">奖品4</div>
<div class="lottery-item">奖品5</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="script.js"></script>
</body>
</html>
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
background-color: #f0f0f0;
}
.lottery-container {
text-align: center;
}
#lottery-wheel {
display: flex;
justify-content: center;
margin-top: 20px;
}
.lottery-item {
padding: 10px 20px;
margin: 0 10px;
background-color: #4CAF50;
color: white;
cursor: pointer;
}
$(document).ready(function() {
$('#start-button').click(function() {
var items = $('#lottery-wheel .lottery-item');
var randomIndex = Math.floor(Math.random() * items.length);
var selectedItem = items.eq(randomIndex);
// 动画效果
items.removeClass('active');
selectedItem.addClass('active');
// 显示中奖结果
alert('恭喜你获得了:' + selectedItem.text());
});
});
通过以上代码和解释,你可以实现一个简单的抽奖特效,并根据需要进行调整和优化。
没有搜到相关的文章