goto.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. $(".feedback-slider1").slick({
  2. dots: true,
  3. dotsClass: 'slick-dots',
  4. speed: 1000,
  5. swipe: true,
  6. });
  7. $(".banner-slider").slick({
  8. dotsClass: 'slick-dots',
  9. speed: 1000,
  10. swipe: true,
  11. });
  12. $.fn.serializeObject = function () {
  13. var o = {};
  14. var a = this.serializeArray();
  15. o["id"] = 0;
  16. o["time_stamp"] = "";
  17. $.each(a, function () {
  18. if (o[this.name]) {
  19. if (!o[this.name].push) {
  20. o[this.name] = [o[this.name]];
  21. }
  22. o[this.name].push(this.value || '');
  23. } else {
  24. o[this.name] = this.value || '';
  25. }
  26. });
  27. return o;
  28. };
  29. // email 格式檢查
  30. $(document).ready(function () {
  31. //E-MAIL格式檢查
  32. $("body").on("change", "#email", function () {
  33. $Emailchecking = IsEmail($("#email").val());
  34. if ($Emailchecking == false) {
  35. alert("請填寫正確的E-MAIL格式");
  36. // $("#email").blur(); //離開焦點
  37. }
  38. })
  39. function IsEmail(email) {
  40. var regex = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
  41. if (!regex.test(email)) {
  42. return false;
  43. } else {
  44. return true;
  45. }
  46. }
  47. });
  48. // phone 格式檢查
  49. $(document).ready(function () {
  50. //phone格式檢查
  51. $("body").on("change", "#phone", function () {
  52. $Phonechecking = IsPhone($("#phone").val());
  53. if ($Phonechecking == false) {
  54. alert("請填寫正確的手機格式");
  55. // $("#email").blur(); //離開焦點
  56. }
  57. })
  58. function IsPhone(phone) {
  59. var regex = /^[0-9]+$/;
  60. if (!regex.test(phone)) {
  61. return false;
  62. } else {
  63. return true;
  64. }
  65. }
  66. });
  67. $(".contact-form1").submit(function (e) {
  68. /* var formRef = $('#form1').serializeArray();
  69. var jsonString = JSON.stringify(formRef);*/
  70. var jsonInfo = $('.contact-form1').serializeObject();
  71. var jsonString = JSON.stringify(jsonInfo);
  72. // email 格式檢查
  73. $.ajax({
  74. type: 'POST',
  75. url: 'https://go.hhh.com.tw:8001/deco_request_detail',
  76. data: jsonString,
  77. dataType: 'json',
  78. success: function (data) {
  79. console.log('送出成功: ' + data);
  80. if (data == 0) {
  81. alert("送出成功");
  82. } else if (data == 1) {
  83. alert("此email已填過表單");
  84. } else if (data == 2) {
  85. alert("此phone已填過表單");
  86. } else if (data == 3) {
  87. alert("此email、phone已填過表單");
  88. }
  89. },
  90. beforeSend: function () {
  91. console.log('beforeSend');
  92. },
  93. complete: function () {
  94. console.log('complete');
  95. },
  96. error: function (jqXHR, textStatus, errorThrown) {
  97. console.log(JSON.stringify(jqXHR));
  98. console.log("AJAX errr: " + textStatus + ' : ' + errorThrown);
  99. console.log('送出失敗: ' + jqXHR.responseText);
  100. }
  101. });
  102. return false;
  103. });
  104. $("*").each(function (index, element) {
  105. // 此元素被點選後執行
  106. $(this).click(function (e) {
  107. // 取得被點選元素的屬性:data-gt-target
  108. var target = $(this).attr("data-gt-target");
  109. var duration = $(this).attr("data-gt-duration");
  110. var offset = $(this).attr("data-gt-offset");
  111. // JS 語法:判斷式
  112. // if (條件) {程式區塊}
  113. // 當條件成立,會執行程式區塊
  114. // 如果 目標有資料 才會執行 { } 內的程式
  115. // 避免出現 undefine (未定義 - 不存在的資料)
  116. if (target) {
  117. //console.log("目標:" + target);
  118. //console.log("時間:" + duration);
  119. //console.log("位移:" + offset);
  120. // 上方位置 = 目標區塊.位移().上方位置
  121. var top = $(target).offset().top;
  122. //console.log("要前往元素的上方位置:" + top);
  123. // 網頁元素.停止().動畫({ 上方捲動:指定元素 - 位移},持續時間)
  124. // parseInt() 將文字轉為數字
  125. $("html").stop().animate({
  126. scrollTop: top - offset
  127. }, parseInt(duration));
  128. }
  129. });
  130. });
  131. // 避免動畫與使用者滾輪衝突
  132. // html 在滾動滾輪時 停止 html 所有效果
  133. $("html").on("mousewheel", function () {
  134. $("html").stop();
  135. });