goto.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. // menu彈跳視窗
  2. $("#menu-box2").hide();
  3. $("#menu-box").hide();
  4. $("#menu-btn1").click(function () {
  5. $("#menu-box").fadeToggle("slow");
  6. $("#menu-box2").slideToggle("slow");
  7. });
  8. $(".feedback-slider1").slick({
  9. dots: true,
  10. dotsClass: 'slick-dots',
  11. speed: 1000,
  12. swipe: true,
  13. });
  14. $(".banner-slider").slick({
  15. dots: true,
  16. dotsClass: 'slick-dots',
  17. speed: 1000,
  18. swipe: true,
  19. });
  20. $(".link").click(function () {
  21. $("#menu-box2").fadeOut("slow", function () {
  22. // Animation complete.
  23. });
  24. });
  25. $.fn.serializeObject = function () {
  26. var o = {};
  27. var a = this.serializeArray();
  28. o["id"] = 0;
  29. o["time_stamp"] = "";
  30. $.each(a, function () {
  31. if (o[this.name]) {
  32. if (!o[this.name].push) {
  33. o[this.name] = [o[this.name]];
  34. }
  35. o[this.name].push(this.value || '');
  36. } else {
  37. o[this.name] = this.value || '';
  38. }
  39. });
  40. return o;
  41. };
  42. $(".contact-form1").submit(function (e) {
  43. /* var formRef = $('#form1').serializeArray();
  44. var jsonString = JSON.stringify(formRef);*/
  45. var jsonInfo = $('.contact-form1').serializeObject();
  46. var jsonString = JSON.stringify(jsonInfo);
  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. $(document).ready(function(){
  79. //E-MAIL格式檢查
  80. $("body").on("change", "#email", function (){
  81. $Emailchecking=IsEmail($("#email").val());
  82. if($Emailchecking==false){
  83. alert("請填寫正確的E-MAIL格式");
  84. $("#email").blur(); //離開焦點
  85. }
  86. })
  87. function IsEmail(email) {
  88. var regex = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
  89. if(!regex.test(email)) {
  90. return false;
  91. }else{
  92. return true;
  93. }
  94. }
  95. });
  96. $("*").each(function (index, element) {
  97. // 此元素被點選後執行
  98. $(this).click(function (e) {
  99. // 取得被點選元素的屬性:data-gt-target
  100. var target = $(this).attr("data-gt-target");
  101. var duration = $(this).attr("data-gt-duration");
  102. var offset = $(this).attr("data-gt-offset");
  103. // JS 語法:判斷式
  104. // if (條件) {程式區塊}
  105. // 當條件成立,會執行程式區塊
  106. // 如果 目標有資料 才會執行 { } 內的程式
  107. // 避免出現 undefine (未定義 - 不存在的資料)
  108. if (target) {
  109. //console.log("目標:" + target);
  110. //console.log("時間:" + duration);
  111. //console.log("位移:" + offset);
  112. // 上方位置 = 目標區塊.位移().上方位置
  113. var top = $(target).offset().top;
  114. //console.log("要前往元素的上方位置:" + top);
  115. // 網頁元素.停止().動畫({ 上方捲動:指定元素 - 位移},持續時間)
  116. // parseInt() 將文字轉為數字
  117. $("html").stop().animate({
  118. scrollTop: top - offset
  119. }, parseInt(duration));
  120. }
  121. });
  122. });
  123. // 避免動畫與使用者滾輪衝突
  124. // html 在滾動滾輪時 停止 html 所有效果
  125. $("html").on("mousewheel", function () {
  126. $("html").stop();
  127. });