goto.js 3.8 KB

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