goto.js 4.3 KB

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