main.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. window.onload = function() {
  2. window.addEventListener('scroll', function() {
  3. var scrollBarTop = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop; // 滚动条离页面顶端的距离
  4. var targetTop = document.getElementsByClassName('successCase')[0].offsetTop // 目标元素离页面顶端的距离
  5. //console.log(scrollBarTop)
  6. // 如果目标元素离页面顶端的距离小于视窗高度+滚动条离页面顶端的距离
  7. // 则表示已滚动到目标元素位置
  8. if(targetTop < scrollBarTop ) {
  9. $('.customer-btn').show()
  10. }else{
  11. $('.customer-btn').hide();
  12. }
  13. })
  14. }
  15. $(function() {
  16. //返回顶部
  17. $("#back-top").click(function() {
  18. _czc.push(["_trackEvent",'获取减税方案','点击']);
  19. var a = $('.send-form').offset().top
  20. $('body,html').animate({
  21. scrollTop: a-160
  22. }, 1000);
  23. return false;
  24. });
  25. //电话咨询
  26. $("#callPhone").click(function() {
  27. _czc.push(["_trackEvent",'电话咨询','点击']);
  28. });
  29. //联系客服
  30. $("#kefu").click(function() {
  31. is_weixin()?
  32. layer.open({
  33. title: [
  34. '保存图片或者长按二维码识别添加微信好友',
  35. 'background-color: #2E7BDA; color:#fff;'
  36. ],
  37. content: "<img src='./assets/kefu.png' style='width:4rem;height:4rem;' alt=''></br><text>微信号:A0rainA0</text>"
  38. }):
  39. layer.open({
  40. title: [
  41. '保存图片,在微信识别二维码添加好友',
  42. 'background-color: #2E7BDA; color:#fff;'
  43. ],
  44. content: "<img src='./assets/kefu.png' style='width:4rem;height:4rem;' alt=''></br><text>微信号:A0rainA0</text>"
  45. });
  46. });
  47. //表单提交
  48. $('#sendForm').submit(function() {
  49. event.preventDefault();//防止默认事件行为
  50. var contactName = $('#contactName').val()
  51. var contactPhone = $('#contactPhone').val()
  52. if(!contactName){
  53. layer.open({
  54. content: '请填写联系人姓名',
  55. style: 'width:auto; height:auto; font-size:0.32rem; background-color:#494949; color:#fff;',
  56. shade: false,
  57. time: 1
  58. });
  59. }else if(!contactPhone){
  60. layer.open({
  61. content: '请填写手机号码',
  62. style: 'width:auto; height:auto; font-size:0.32rem; background-color:#494949; color:#fff;',
  63. shade: false,
  64. time: 1
  65. });
  66. }else{
  67. _czc.push(["_trackEvent",'马上获取减税方案','点击']);
  68. $.ajax({
  69. type: 'POST',
  70. url: window.location.protocol + '//www.wodeshebao.com/sbw/ent/sign',
  71. data: $("#sendForm").serialize(),
  72. dataType: 'json',
  73. success: function(resp) {
  74. if (resp.code == 200) {
  75. window.location.replace("suc.html")
  76. } else {
  77. layer.open({
  78. content: resp.msg,
  79. style: 'width:auto; height:auto; font-size:0.32rem; background-color:#494949; color:#fff;',
  80. shade: false,
  81. time: 3
  82. });
  83. }
  84. }
  85. });
  86. }
  87. })
  88. });
  89. // isweixin
  90. function is_weixin(){
  91. var ua = navigator.userAgent.toLowerCase();
  92. if (ua.match(/MicroMessenger/i) == "micromessenger") {
  93. //console.log("微信")
  94. return true;
  95. } else {
  96. //console.log("其他浏览器")
  97. return false;
  98. }
  99. }