天天看點

自己動手敲代碼,輕松實作線上電影票選座功能

最近大家都在談論一部熱播的電影《我不是藥神》,由于故事貼近生活,貼近到每個人都能切身體會到演員的情緒,因為感同身受,是以就更能夠引起共鳴。影片在批判社會現實、揭露尖銳沖突,反映社會底層人民得不到滿足而不顧法律正義的同時,又給人們看到改變社會現實的希望與藥方。

于是紛紛湧入影院,希望一起探讨這個話題。于是,美團影院、QQ購票,貓眼購票等等成是我們購票的首選。

網上購票如此的友善,那麼我們能用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()

以上就是大緻的電影院選票功能的實作。

轉載于:https://blog.51cto.com/13881968/2151748