goto.js 3.6 KB

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