自己动手敲代码,轻松实现在线电影票选座功能

最近大家都在谈论一部热播的电影《我不是药神》,由于故事贴近生活,贴近到每个人都能切身体会到演员的情绪,因为感同身受,所以就更能够引起共鸣。影片在批判社会现实、揭露尖锐矛盾,反映社会底层人民得不到满足而不顾法律正义的同时,又给人们看到改变社会现实的希望与药方。

于是纷纷涌入影院,希望一起探讨这个话题。于是,美团影院、QQ购票,猫眼购票等等成是我们购票的首选。


网上购票如此的方便,那么我们能用HTML5+JavaScript实现一款在线电影票的选票功能吗?


答案是肯定的,今天我们就来借助jQuery的jQuery-Seat-Charts插件来实现在线电影票选座功能。


本案例(科文中心电影院)支持在线选座,票数统计,结算等功能。


1.jpg


根据上面的实例,我相信你们可以制作一款针对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()


以上就是大致的电影院选票功能的实现。

猜你喜欢

转载自blog.51cto.com/13881968/2151748
今日推荐