goto.js 4.4 KB

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