经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » JS/JS库/框架 » jQuery » 查看文章
jQuery实现影院选座订座效果
来源:jb51  时间:2021/4/12 19:00:19  对本文有异议

jQuery实现影院选座订座效果,供大家参考,具体内容如下

效果如下:

代码如下:

  1. <!DOCTYPE html>
  2. <html>
  3.  
  4. <head>
  5. <meta charset="utf-8">
  6. <meta name="viewport" content="width=device-width; initial-scale=1.0">
  7. <title>jQuery影院选座订座效果代码</title>
  8. <meta name="keywords" content="jQuery,选座">
  9.  
  10. <style type="text/css">
  11. .demo {
  12. width: 700px;
  13. margin: 40px auto 0 auto;
  14. min-height: 450px;
  15. }
  16. @media screen and (max-width: 360px) {
  17. .demo {
  18. width: 340px
  19. }
  20. }
  21. .front {
  22. width: 300px;
  23. margin: 5px 32px 45px 32px;
  24. background-color: #f0f0f0;
  25. color: #666;
  26. text-align: center;
  27. padding: 3px;
  28. border-radius: 5px;
  29. }
  30. .booking-details {
  31. float: right;
  32. position: relative;
  33. width: 200px;
  34. height: 450px;
  35. }
  36. .booking-details h3 {
  37. margin: 5px 5px 0 0;
  38. font-size: 16px;
  39. }
  40. .booking-details p {
  41. line-height: 26px;
  42. font-size: 16px;
  43. color: #999
  44. }
  45. .booking-details p span {
  46. color: #666
  47. }
  48. div.seatCharts-cell {
  49. color: #182C4E;
  50. height: 25px;
  51. width: 25px;
  52. line-height: 25px;
  53. margin: 3px;
  54. float: left;
  55. text-align: center;
  56. outline: none;
  57. font-size: 13px;
  58. }
  59. div.seatCharts-seat {
  60. color: #fff;
  61. cursor: pointer;
  62. -webkit-border-radius: 5px;
  63. -moz-border-radius: 5px;
  64. border-radius: 5px;
  65. }
  66. div.seatCharts-row {
  67. height: 35px;
  68. }
  69. div.seatCharts-seat.available {
  70. background-color: #B9DEA0;
  71. }
  72. div.seatCharts-seat.focused {
  73. background-color: #76B474;
  74. border: none;
  75. }
  76. div.seatCharts-seat.selected {
  77. background-color: #E6CAC4;
  78. }
  79. div.seatCharts-seat.unavailable {
  80. background-color: #472B34;
  81. cursor: not-allowed;
  82. }
  83. div.seatCharts-container {
  84. border-right: 1px dotted #adadad;
  85. width: 400px;
  86. padding: 20px;
  87. float: left;
  88. }
  89. div.seatCharts-legend {
  90. padding-left: 0px;
  91. position: absolute;
  92. bottom: 16px;
  93. }
  94. ul.seatCharts-legendList {
  95. padding-left: 0px;
  96. }
  97. .seatCharts-legendItem {
  98. float: left;
  99. width: 90px;
  100. margin-top: 10px;
  101. line-height: 2;
  102. }
  103. span.seatCharts-legendDescription {
  104. margin-left: 5px;
  105. line-height: 30px;
  106. }
  107. .checkout-button {
  108. display: block;
  109. width: 80px;
  110. height: 24px;
  111. line-height: 20px;
  112. margin: 10px auto;
  113. border: 1px solid #999;
  114. font-size: 14px;
  115. cursor: pointer
  116. }
  117. #selected-seats {
  118. max-height: 150px;
  119. overflow-y: auto;
  120. overflow-x: none;
  121. width: 200px;
  122. }
  123. #selected-seats li {
  124. float: left;
  125. width: 72px;
  126. height: 26px;
  127. line-height: 26px;
  128. border: 1px solid #d3d3d3;
  129. background: #f7f7f7;
  130. margin: 6px;
  131. font-size: 14px;
  132. font-weight: bold;
  133. text-align: center
  134. }
  135. </style>
  136.  
  137. </head>
  138.  
  139. <body>
  140.  
  141.  
  142. <div id="main">
  143.  
  144. <div class="demo">
  145. <div id="seat-map">
  146. <div class="front">屏幕</div>
  147. </div>
  148. <div class="booking-details">
  149. <p>影片:<span>星际穿越</span></p>
  150. <p>时间:<span>11月14日 21:00</span></p>
  151. <p>座位:</p>
  152. <ul id="selected-seats"></ul>
  153. <p>票数:<span id="counter">0</span></p>
  154. <p>总计:<b><span id="total">0</span></b></p>
  155.  
  156. <button class="checkout-button">确定购买</button>
  157.  
  158. <div id="legend"></div>
  159. </div>
  160. <div style="clear:both"></div>
  161. </div>
  162.  
  163. <br />
  164. </div>
  165. <script type="text/javascript" src="http://code.jquery.com/jquery-1.12.1.min.js"></script>
  166. <script type="text/javascript" src="jquery.seat-charts.min.js"></script>
  167. <script type="text/javascript">
  168. var price = 70; /*票价*/
  169. $(document).ready(function() {
  170. var $cart = $('#selected-seats'),
  171. /*座位区*/
  172. $counter = $('#counter'),
  173. /*票数*/
  174. $total = $('#total'); /*总计金额*/
  175.  
  176. var sc = $('#seat-map').seatCharts({
  177. map: [ /*座位图*/
  178. 'aaaaaaaaaa',
  179. 'aaaaaaaaaa',
  180. '__________',
  181. 'aaaaaaaa__',
  182. 'aaaaaaaaaa',
  183. 'aaaaaaaaaa',
  184. 'aaaaaaaaaa',
  185. 'aaaaaaaaaa',
  186. 'aaaaaaaaaa',
  187. 'aa__aa__aa'
  188. ],
  189. naming: {
  190. top: false,
  191. getLabel: function(character, row, column) {
  192. return column;
  193. }
  194. },
  195. legend: { /*定义图例*/
  196. node: $('#legend'),
  197. items: [
  198. ['a', 'available', '可选座'],
  199. ['a', 'unavailable', '已售出']
  200. ]
  201. },
  202. click: function() { /*点击事件*/
  203. if (this.status() == 'available') { /*可选座*/
  204. $('<li>' + (this.settings.row + 1) + '排' + this.settings.label + '座</li>')
  205. .attr('id', 'cart-item-' + this.settings.id)
  206. .data('seatId', this.settings.id)
  207. .appendTo($cart);
  208.  
  209. $counter.text(sc.find('selected').length + 1);
  210. $total.text(recalculateTotal(sc) + price);
  211.  
  212. return 'selected';
  213. } else if (this.status() == 'selected') { /*已选中*/
  214. /*更新数量*/
  215. $counter.text(sc.find('selected').length - 1);
  216. /*更新总计*/
  217. $total.text(recalculateTotal(sc) - price);
  218.  
  219. /*删除已预订座位*/
  220. $('#cart-item-' + this.settings.id).remove();
  221. /*可选座*/
  222. return 'available';
  223. } else if (this.status() == 'unavailable') { /*已售出*/
  224. return 'unavailable';
  225. } else {
  226. return this.style();
  227. }
  228. }
  229. });
  230. /*已售出的座位*/
  231. sc.get(['1_2', '4_4', '4_5', '6_6', '6_7', '8_5', '8_6', '8_7', '8_8', '10_1', '10_2']).status('unavailable');
  232.  
  233. });
  234. /*计算总金额*/
  235. function recalculateTotal(sc) {
  236. var total = 0;
  237. sc.find('selected').each(function() {
  238. total += price;
  239. });
  240.  
  241. return total;
  242. }
  243. </body>
  244.  
  245. </html>

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持w3xue。

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号