Java基础、中级、高级、架构面试资料

使用jQuery-Seat-Charts插件实现在线电影票选座功能

HTML5 herman 5906浏览 0评论
公告:“业余草”微信公众号提供免费CSDN下载服务(只下Java资源),关注业余草微信公众号,添加作者微信:xttblog2,发送下载链接帮助你免费下载!
本博客日IP超过2000,PV 3000 左右,急需赞助商。
极客时间所有课程通过我的二维码购买后返现24元微信红包,请加博主新的微信号:xttblog2,之前的微信号好友位已满,备注:返现
受密码保护的文章请关注“业余草”公众号,回复关键字“0”获得密码
所有面试题(java、前端、数据库、springboot等)一网打尽,请关注文末小程序
视频教程免费领
腾讯云】1核2G5M轻量应用服务器50元首年,高性价比,助您轻松上云

最近《战狼2》大火,创造了50亿的票房,打破了多个记录。我相信大部分的小伙伴们都已经去看过了,而且有一部分就是在网上购买的电影票,例如淘宝淘票票在线选票的功能。网上购票如此的方便,那么我们能用HTML5+JavaScript实现一款在线电影票的选票功能吗?
答案是肯定的,今天我们就来借助jQuery的jQuery-Seat-Charts插件来实现在线电影票选座功能。本案例(科文中心电影院)支持在线选座,票数统计,结算等功能。

仿电影票选座效果

根据上面的实例,我相信你们可以制作一款针对12306的在线选火车票的效果,汽车票也一样。

下面看看具体的实现代码:

<div class="demo"> 
       <div id="seat-map"> 
        <div class="front">屏幕</div>                     
    </div> 
    <div class="booking-details"> 
        <p>影片:<span>星际穿越3D</span></p> 
        <p>时间:<span>11月14日 21:00</span></p> 
        <p>座位:</p> 
        <ul id="selected-seats"></ul> 
        <p>票数:<span id="counter">0</span></p> 
        <p>总计:<b>¥<span id="total">0</span></b></p>         
        <button class="checkout-button">确定购买</button>         
        <div id="legend"></div> 
    </div> 
</div> 

剩下的最主要的是使用CSS将页面中的各个元素美化。包括电影院布局,座位布局,选票功能实现,实时统计票数等功能。

.front{width: 300px;margin: 5px 32px 45px 32px;background-color: #f0f0f0; color: #666;text-align: center;padding: 3px;border-radius: 5px;} 
.booking-details {float: right;position: relative;width:200px;height: 450px; } 
.booking-details h3 {margin: 5px 5px 0 0;font-size: 16px;} 
.booking-details p{line-height:26px; font-size:16px; color:#999} 
.booking-details p span{color:#666} 
div.seatCharts-cell {color: #182C4E;height: 25px;width: 25px;line-height: 25px;margin: 3px;float: left;text-align: center;outline: none;font-size: 13px;} 
div.seatCharts-seat {color: #fff;cursor: pointer;-webkit-border-radius:5px;-moz-border-radius:5px;border-radius: 5px;} 
div.seatCharts-row {height: 35px;} 
div.seatCharts-seat.available {background-color: #B9DEA0;} 
div.seatCharts-seat.focused {background-color: #76B474;border: none;} 
div.seatCharts-seat.selected {background-color: #E6CAC4;} 
div.seatCharts-seat.unavailable {background-color: #472B34;cursor: not-allowed;} 
div.seatCharts-container {border-right: 1px dotted #adadad;width: 400px;padding: 20px;float: left;} 
div.seatCharts-legend {padding-left: 0px;position: absolute;bottom: 16px;} 
ul.seatCharts-legendList {padding-left: 0px;} 
.seatCharts-legendItem{float:left; width:90px;margin-top: 10px;line-height: 2;} 
span.seatCharts-legendDescription {margin-left: 5px;line-height: 30px;} 
.checkout-button {display: block;width:80px; height:24px; line-height:20px;margin: 10px auto;border:1px solid #999;font-size: 14px; cursor:pointer} 
#selected-seats {max-height: 150px;overflow-y: auto;overflow-x: none;width: 200px;} 
#selected-seats li{float:left; width:72px; height:26px; line-height:26px; border:1px solid #d3d3d3; background:#f7f7f7; margin:6px; font-size:14px; font-weight:bold; text-align:center} 

最后引入我们的jQuery的jQuery-Seat-Charts插件

<script type="text/javascript" src="jquery.js"></script> 
<script type="text/javascript" src="jquery.seat-charts.min.js"></script> 

在调用该插件的seatCharts()方法即可实现电影票选票功能的渲染。

$('#seat-map').seatCharts()

以上就是大致的电影院选票功能的实现。完整的代码已共享在github:https://github.com/mateuszmarkowski/jQuery-Seat-Charts

业余草公众号

最后,欢迎关注我的个人微信公众号:业余草(yyucao)!可加作者微信号:xttblog2。备注:“1”,添加博主微信拉你进微信群。备注错误不会同意好友申请。再次感谢您的关注!后续有精彩内容会第一时间发给您!原创文章投稿请发送至532009913@qq.com邮箱。商务合作也可添加作者微信进行联系!

本文原文出处:业余草: » 使用jQuery-Seat-Charts插件实现在线电影票选座功能