script.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. $('.owl-carousel-pc').owlCarousel({
  2. loop:true,
  3. margin: 0,
  4. nav:true,
  5. autoWidth:true,
  6. mouseDrag: true,
  7. touchDrag: true,
  8. smartSpeed: 1000,
  9. autoplay: true,
  10. autoplayTimeout: 9000,
  11. autoplayHoverPause: false,
  12. responsive:{
  13. 0:{
  14. items:1
  15. },
  16. 600:{
  17. items:1
  18. },
  19. 1200:{
  20. items:2
  21. }
  22. }
  23. });
  24. $('.owl-carousel-mb').owlCarousel({
  25. loop:true,
  26. margin: 0,
  27. nav:true,
  28. mouseDrag: true,
  29. touchDrag: true,
  30. smartSpeed: 0,
  31. autoplay: true,
  32. autoplayTimeout: 9000,
  33. autoplayHoverPause: false,
  34. responsive:{
  35. 0:{
  36. items:1
  37. },
  38. 600:{
  39. items:1
  40. },
  41. 1000:{
  42. items:2
  43. }
  44. }
  45. });
  46. $('.owl-nav').css('display', 'none');
  47. $('designers__card').click(function(e){
  48. console.log(e);
  49. let url = e.target.dataset.address;
  50. document.location = url;
  51. })
  52. //jQuery time
  53. var current_fs, next_fs, previous_fs; //fieldsets
  54. var left, opacity, scale; //fieldset properties which we will animate
  55. var animating; //flag to prevent quick multi-click glitches
  56. $(".next").click(function(){
  57. if( !validate() ){
  58. return false;
  59. }
  60. if(animating) return false;
  61. animating = true;
  62. current_fs = $(this).parent();
  63. next_fs = $(this).parent().next();
  64. //activate next step on progressbar using the index of next_fs
  65. $("#progressbar li").eq($("fieldset").index(next_fs)).addClass("active");
  66. //show the next fieldset
  67. next_fs.show();
  68. //hide the current fieldset with style
  69. current_fs.animate({opacity: 0}, {
  70. step: function(now, mx) {
  71. //as the opacity of current_fs reduces to 0 - stored in "now"
  72. //1. scale current_fs down to 80%
  73. scale = 1 - (1 - now) * 0.2;
  74. //2. bring next_fs from the right(50%)
  75. left = (now * 50)+"%";
  76. //3. increase opacity of next_fs to 1 as it moves in
  77. opacity = 1 - now;
  78. current_fs.css({
  79. 'transform': 'scale('+scale+')',
  80. 'position': 'absolute'
  81. });
  82. next_fs.css({'left': left, 'opacity': opacity});
  83. },
  84. duration: 800,
  85. complete: function(){
  86. current_fs.hide();
  87. animating = false;
  88. },
  89. //this comes from the custom easing plugin
  90. easing: 'easeInOutBack'
  91. });
  92. });
  93. $(".previous").click(function(){
  94. if(animating) return false;
  95. animating = true;
  96. current_fs = $(this).parent();
  97. previous_fs = $(this).parent().prev();
  98. //de-activate current step on progressbar
  99. $("#progressbar li").eq($("fieldset").index(current_fs)).removeClass("active");
  100. //show the previous fieldset
  101. previous_fs.show();
  102. //hide the current fieldset with style
  103. current_fs.animate({opacity: 0}, {
  104. step: function(now, mx) {
  105. //as the opacity of current_fs reduces to 0 - stored in "now"
  106. //1. scale previous_fs from 80% to 100%
  107. scale = 0.8 + (1 - now) * 0.2;
  108. //2. take current_fs to the right(50%) - from 0%
  109. left = ((1-now) * 50)+"%";
  110. //3. increase opacity of previous_fs to 1 as it moves in
  111. opacity = 1 - now;
  112. current_fs.css({'left': left});
  113. previous_fs.css({'transform': 'scale('+scale+')', 'opacity': opacity});
  114. },
  115. duration: 800,
  116. complete: function(){
  117. current_fs.hide();
  118. animating = false;
  119. },
  120. //this comes from the custom easing plugin
  121. easing: 'easeInOutBack'
  122. });
  123. });
  124. $("input[name=submit]").click(function(){
  125. let stop;
  126. console.log($("#msform").serialize());
  127. if( $('input[name="q9"]:visible').val() !== undefined && !$('input[name="q9"]:visible').prop('checked') ) {
  128. stop = 1;
  129. $('#term-error').text('必須同意免責聲明與隱私使用政策');
  130. }else {
  131. stop = 0;
  132. $('#term-error').text('');
  133. }
  134. if(stop == 0) {
  135. alert("送出成功");
  136. }
  137. });
  138. // 依據管道導頁
  139. /* function showThankyou() {
  140. axios.get('http://q.ptt.cx/coffee').then(res => {
  141. if(res.data.coffee == 1) {
  142. document.location = '/a1/index_complete_line.html';
  143. } else {
  144. document.location = '/a1/index_complete_line_after.html';
  145. }
  146. });
  147. // document.location = '/a1/index_complete_line.html';
  148. } */
  149. // 跳離頁面
  150. function show_input_text(checkbox_id, input_id) {
  151. var checkBox = document.getElementById(checkbox_id);
  152. var inp = document.getElementById(input_id);
  153. if (checkBox.checked == true){
  154. inp.style.display = "block";
  155. } else {
  156. inp.style.display = "none";
  157. }
  158. }
  159. function validate() {
  160. function q2_validate() {
  161. let phoneno = /^\d{10}$/;
  162. if( $('input[name="q2"]:visible').val() !== undefined && $('input[name="q2"]:visible').val().length <= 0) {
  163. $('input[name="q2"]:visible').addClass('error');
  164. if( !$('.error-text').length )
  165. $('input.error').after('<p class="error-text">請輸入正確手機號碼</p>');
  166. return false;
  167. } else if($('input[name="q2"]:visible').val() !== undefined && !phoneno.test($('input[name="q2"]:visible').val())){
  168. $('input[name="q2"]:visible').addClass('error');
  169. if( !$('.error-text').length )
  170. $('input.error').after('<p class="error-text">請輸入正確手機號碼</p>');
  171. return false;
  172. }else {
  173. $('input[name="q2"]:visible').removeClass('error');
  174. $('.error-text').remove();
  175. return true;
  176. }
  177. }
  178. function q3_validate() {
  179. let emailPattern = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
  180. if( $('input[name="q3"]:visible').val() !== undefined && $('input[name="q3"]:visible').val().length <= 0) {
  181. $('input[name="q3"]:visible').addClass('error');
  182. if( !$('.error-text').length )
  183. $('input.error').after('<p class="error-text">請輸入E-mail</p>');
  184. return false;
  185. } else if ( $('input[name="q3"]:visible').val() !== undefined && !emailPattern.test($('input[name="q3"]:visible').val()) ){
  186. $('input[name="q3"]:visible').addClass('error');
  187. if( !$('.error-text').length )
  188. $('input.error').after('<p class="error-text">請輸入正確email格式</p>');
  189. return false;
  190. }
  191. else {
  192. $('input[name="q3"]:visible').removeClass('error');
  193. $('.error-text').remove();
  194. return true;
  195. }
  196. }
  197. function q4_validate() {
  198. if( $('input[name="q4"]:visible').val() !== undefined && $('input[name="q4"]:visible').val().length <= 0 ) {
  199. $('input[name="q4"]:visible').addClass('error');
  200. if( !$('.error-text').length )
  201. $('input.error').after('<p class="error-text">請輸入建案名稱</p>');
  202. return false;
  203. }
  204. else {
  205. $('input[name="q4"]:visible').removeClass('error');
  206. $('.error-text').remove();
  207. return true;
  208. }
  209. }
  210. return q2_validate() && q3_validate() && q4_validate();
  211. }