html影院选座模板,jQuery实现影院选座订座效果代码怎么写,包括前段页面显示
时间: 2024-01-27 10:03:37 浏览: 68
以下是一个简单的HTML影院选座模板,使用jQuery实现影院选座订座效果:
HTML代码:
```html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>影院选座模板</title>
<link rel="stylesheet" href="css/seat.css">
</head>
<body>
<div id="seat-map">
<div class="screen">屏幕</div>
<div class="seat">
<span class="seat-label">A</span>
<input type="checkbox" class="seat-select" value="A1">
</div>
<!-- 其他座位 -->
</div>
<div class="seat-info">
<span class="legend available"></span>可选座位
<span class="legend unavailable"></span>已售出座位
<span class="legend selected"></span>已选座位
</div>
<div class="booking-details">
<p>已选座位:</p>
<ul id="selected-seats"></ul>
<p>总计: <b>$<span id="total">0</span></b></p>
<button class="checkout-button">订座</button>
</div>
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script src="js/seat.js"></script>
</body>
</html>
```
CSS代码:
```css
#seat-map {
width: 800px;
margin: 0 auto;
font-size: 0;
}
.seat {
height: 20px;
width: 20px;
background-color: #bbb;
margin: 5px;
display: inline-block;
position: relative;
}
.seat-label {
position: absolute;
top: -15px;
left: 0;
font-size: 14px;
font-weight: bold;
}
.seat-select {
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
opacity: 0;
cursor: pointer;
}
.seat-select:checked+.seat {
background-color: #f9a94d;
}
.seat-select:checked+.seat .seat-label {
color: #fff;
}
.screen {
background-color: #333;
color: #fff;
text-align: center;
font-size: 18px;
font-weight: bold;
height: 30px;
line-height: 30px;
margin-bottom: 20px;
}
.legend {
display: inline-block;
width: 20px;
height: 20px;
margin-right: 10px;
}
.available {
background-color: #bbb;
}
.unavailable {
background-color: #f9a94d;
}
.selected {
background-color: #5cb85c;
}
.booking-details {
margin-top: 50px;
text-align: center;
}
.checkout-button {
background-color: #f9a94d;
color: #fff;
padding: 10px;
border: none;
border-radius: 5px;
cursor: pointer;
margin-top: 20px;
}
.checkout-button:hover {
background-color: #d9892e;
}
```
JavaScript代码:
```javascript
$(document).ready(function () {
var $cart = $('#selected-seats'); // 显示已选座位的ul
var $counter = $('#counter'); // 显示已选座位数量的span
var $total = $('#total'); // 显示总价的span
var sc = $('#seat-map').seatCharts({
map: [ // 座位图
'aaaaaaaaaa',
'aaaaaaaaaa',
'__________',
'aaaaaaaa__',
'aaaaaaaaaa',
'aaaaaaaaaa',
'aaaaaaaaaa',
'aaaaaaaaaa',
'aaaaaaaaaa',
'aa__aa__aa'
],
seats: {
a: { price: 10, classes: 'available' },
// 已售出的座位
s: { price: 10, classes: 'unavailable' },
// 已选中的座位
f: { price: 10, classes: 'selected' }
},
naming: {
top: false,
getLabel: function (character, row, column) {
return column;
}
},
legend: { // 座位状态图例
node: $('#legend'),
items: [
[ 'a', 'available', '可选座位' ],
[ 's', 'unavailable', '已售出座位'],
[ 'f', 'selected', '已选座位']
]
},
click: function () { // 选中座位事件
if (this.status() == 'available') {
$('<li>' + this.settings.label + ': $' + this.data().price + '</li>')
.attr('id', 'cart-item-' + this.settings.id)
.data('seatId', this.settings.id)
.appendTo($cart);
$counter.text(sc.find('selected').length + 1);
$total.text(recalculateTotal(sc) + this.data().price);
return 'selected';
} else if (this.status() == 'selected') {
$('#cart-item-' + this.settings.id).remove();
$counter.text(sc.find('selected').length - 1);
$total.text(recalculateTotal(sc) - this.data().price);
return 'available';
} else {
return this.style();
}
}
});
// 初始化已选座位数量和总价
$counter.text(sc.find('selected').length);
$total.text(recalculateTotal(sc));
function recalculateTotal(sc) { // 计算总价
var total = 0;
sc.find('selected').each(function () {
total += this.data().price;
});
return total;
}
});
```
以上是一个简单的影院选座模板,使用jQuery实现影院选座订座效果。你可以根据需要进行修改和定制化。
阅读全文