common.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. function Common(){
  2. }
  3. Common.prototype.sendAjax = function (obj) {
  4. var that = this
  5. $.ajax({
  6. "type": "post",
  7. "dataType":"json",
  8. "contentType": "application/json",
  9. "url": obj.url,
  10. "data": obj.data,
  11. "success": function(res){
  12. // 请求的回调函数
  13. obj.fun && obj.fun(res)
  14. },
  15. error:function(){
  16. var toastjson = {msg:'网络出错,请稍后再试'};
  17. window.bookSotre.toast(JSON.stringify(toastjson));
  18. }
  19. })
  20. }
  21. Common.prototype.getQueryString = function (name){
  22. if(name){
  23. var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
  24. var r = window.location.search.substr(1).match(reg);
  25. if(r!=null){
  26. return unescape(r[2]);
  27. }
  28. return '';
  29. }else{
  30. return window.location.search
  31. }
  32. }
  33. Common.prototype.logClick = function(obj){
  34. // 客户端打点
  35. try{
  36. window.bookSotre.logClick(obj.module, obj.zone, '', '', JSON.stringify(obj.json || {}));
  37. }catch(err){
  38. console.log(obj)
  39. }
  40. }
  41. // 动画效果
  42. Common.prototype.transitionFun = function(){
  43. if($('.top_item').length < 3){
  44. $('.top_list').hide()
  45. return
  46. }
  47. var tempY = 0
  48. let heightTem = $('.top_item').height()
  49. var timers = setInterval(function(){
  50. tempY -= 1
  51. // if(tempY < -10 && tempY >= -30){
  52. // $('.top_item').eq(1).addClass('transition_item')
  53. // }else if(tempY < -50 && tempY > -100 ){
  54. // $('.top_item').eq(2).addClass('transition_item')
  55. // }
  56. // else if(tempY <= -100){
  57. // $('.top_list').find('.top_item').removeClass('transition_item')
  58. // tempY += $('.top_list').find('.top_item').eq(1).position().top
  59. // $('.top_item').eq(3).addClass('transition_item')
  60. // $('.top_list').find('.top_item').eq(0).appendTo($('.top_list'))
  61. // }
  62. if(tempY <= -heightTem){
  63. tempY += $('.top_list').find('.top_item').eq(1).position().top
  64. $('.top_list').find('.top_item').eq(0).appendTo($('.top_list'))
  65. }
  66. $('.top_list').css({
  67. 'transform': 'translateY('+tempY+'px)'
  68. })
  69. },30)
  70. }
  71. // 公用点击事件
  72. Common.prototype.handleClick = function(){
  73. var that = this
  74. // 关闭活弹层
  75. $('body').on('click', '.common_pop .pop_close', function(){
  76. $(this).parents('.common_pop').hide()
  77. })
  78. // 打开活动规则
  79. $('.top_change_rule').click(function(){
  80. $('.charge_rule_pop').show()
  81. })
  82. // 去我的挑战页面
  83. $('.top_my_change').click(function(){
  84. var urlJson = {
  85. url: '/index/recharge/myRecharge',
  86. title: '我的挑战'
  87. }
  88. try{
  89. that.goUrl({
  90. url: '/index/recharge/myRecharge'+window.location.search
  91. })
  92. // window.bookSotre.bookStoreClick('', '4', '', JSON.stringify(urlJson));
  93. }catch(err){
  94. that.goUrl({
  95. url: '/index/recharge/myRecharge'+window.location.search
  96. })
  97. }
  98. })
  99. }
  100. // 客户端js
  101. Common.prototype.goUrl = function(obj){
  102. var url = window.location.origin + obj.url + window.location.search
  103. var json = {
  104. url: url,
  105. paramAppend: true
  106. }
  107. try{
  108. window.location.href = url
  109. // window.bookSotre.bookStoreClick('','4','',JSON.stringify(json))
  110. }catch(err){
  111. window.location.href = url
  112. // window.location.replace(url)
  113. }
  114. }