You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

tabbar.js 2.2 KiB

3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. (function($) {
  2. window.tabbar = window.tabbar || {};
  3. var initData = {};
  4. var t_tabAry =[];
  5. window.tabbar.init = function(initData, callBack) {
  6. var t_index = initData['index'] ? initData['index'] : 0;
  7. var arr = [{
  8. title: '首页',
  9. img: 'url(images/tabbar/shouye_n.png)',
  10. sel_img: 'url(images/tabbar/shouye_s.png)'
  11. }, {
  12. title: '目的地',
  13. img: 'url(images/tabbar/mudidi_n.png)',
  14. sel_img: 'url(images/tabbar/mudidi_s.png)'
  15. }, {
  16. title: '行程',
  17. img: 'url(images/tabbar/xingcheng_n.png)',
  18. sel_img: 'url(images/tabbar/xingcheng_s.png)'
  19. }, {
  20. title: '我的',
  21. img: 'url(images/tabbar/wode_n.png)',
  22. sel_img: 'url(images/tabbar/wode_s.png)'
  23. }];
  24. t_tabAry = initData['tabAry'] ? initData['tabAry'] : arr;
  25. createHTML(t_tabAry);
  26. if(t_index > t_tabAry.length) {
  27. t_index = 0;
  28. }
  29. function createHTML(t_tabAry) {
  30. var html = '';
  31. t_tabAry.forEach(function(dict, index) {
  32. var tempHTML = '<div class="ub-f1 ub ub-ver tx-c controller ub-pc ub-ac" data-index=' + index + ' >' +
  33. '<div style="background-image:'+dict.img+';background-repeat: no-repeat;background-size: 100% 100%;width:0.25rem;height:0.25rem;margin-bottom:0.03rem;"></div>' +
  34. '<div class="select_title">' + dict.title + '</div>' +
  35. '</div>'
  36. html += tempHTML;
  37. })
  38. $('.tabbar').html(html);
  39. }
  40. $('.controller').each(function(index, domE) {
  41. $(this).children().eq(1).removeClass('select_title');
  42. $(this).children().eq(1).addClass('normal_title');
  43. if(index == t_index) {
  44. $(this).children().eq(0).css('background-image',t_tabAry[t_index].sel_img);
  45. $(this).children().eq(1).removeClass('normal_title');
  46. $(this).children().eq(1).addClass('select_title');
  47. }
  48. });
  49. $('.controller').on('click', function() {
  50. var c_index = $(this).attr('data-index')-0;
  51. if(typeof(callBack) == 'function') {
  52. callBack(c_index);
  53. }
  54. switch(c_index) {
  55. case 0:
  56. window.location.href = './travel_book.html';
  57. break;
  58. case 1:
  59. window.location.href = './end_area.html';
  60. break;
  61. case 2:
  62. window.location.href = './trip_list.html';
  63. break;
  64. case 3:
  65. window.location.href = './travel_book.html';
  66. break;
  67. default:
  68. break;
  69. }
  70. })
  71. }
  72. })(jQuery)