scripts.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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. $("html,body").animate(
  63. {
  64. scrollTop: $(".personal__box").offset().top
  65. },
  66. 0
  67. );
  68. current_fs = $(this).parent();
  69. next_fs = $(this).parent().next();
  70. //activate next step on progressbar using the index of next_fs
  71. $("#progressbar li").eq($("fieldset").index(next_fs)).addClass("active");
  72. //show the next fieldset
  73. next_fs.show();
  74. //hide the current fieldset with style
  75. current_fs.animate({opacity: 0}, {
  76. step: function(now, mx) {
  77. //as the opacity of current_fs reduces to 0 - stored in "now"
  78. //1. scale current_fs down to 80%
  79. scale = 1 - (1 - now) * 0.2;
  80. //2. bring next_fs from the right(50%)
  81. left = (now * 50)+"%";
  82. //3. increase opacity of next_fs to 1 as it moves in
  83. opacity = 1 - now;
  84. current_fs.css({
  85. 'transform': 'scale('+scale+')',
  86. 'position': 'absolute'
  87. });
  88. next_fs.css({'left': left, 'opacity': opacity});
  89. },
  90. duration: 800,
  91. complete: function(){
  92. current_fs.hide();
  93. animating = false;
  94. },
  95. //this comes from the custom easing plugin
  96. easing: 'easeInOutBack'
  97. });
  98. });
  99. $(".previous").click(function(){
  100. if(animating) return false;
  101. animating = true;
  102. $("html,body").animate(
  103. {
  104. scrollTop: $(".personal__box").offset().top
  105. },
  106. 0
  107. );
  108. current_fs = $(this).parent();
  109. previous_fs = $(this).parent().prev();
  110. //de-activate current step on progressbar
  111. $("#progressbar li").eq($("fieldset").index(current_fs)).removeClass("active");
  112. //show the previous fieldset
  113. previous_fs.show();
  114. //hide the current fieldset with style
  115. current_fs.animate({opacity: 0}, {
  116. step: function(now, mx) {
  117. //as the opacity of current_fs reduces to 0 - stored in "now"
  118. //1. scale previous_fs from 80% to 100%
  119. scale = 0.8 + (1 - now) * 0.2;
  120. //2. take current_fs to the right(50%) - from 0%
  121. left = ((1-now) * 50)+"%";
  122. //3. increase opacity of previous_fs to 1 as it moves in
  123. opacity = 1 - now;
  124. current_fs.css({'left': left});
  125. previous_fs.css({'transform': 'scale('+scale+')', 'opacity': opacity});
  126. },
  127. duration: 800,
  128. complete: function(){
  129. current_fs.hide();
  130. animating = false;
  131. },
  132. //this comes from the custom easing plugin
  133. easing: 'easeInOutBack'
  134. });
  135. });
  136. function reload() {
  137. console.log("pass");
  138. location.reload();
  139. }
  140. $("input[name=submit]").click(function(){
  141. let stop;
  142. console.log($("#msform").serialize());
  143. if( $('input[name="q9"]:visible').val() !== undefined && !$('input[name="q9"]:visible').prop('checked') ) {
  144. stop = 1;
  145. $('#term-error').text('必須同意免責聲明與隱私使用政策');
  146. }else {
  147. stop = 0;
  148. $('#term-error').text('');
  149. }
  150. if(stop == 0) {
  151. alert("我們已將5萬裝修折價券寄至您所填寫的電子信箱,請確認電子信箱,謝謝!");
  152. }
  153. });
  154. // 依據管道導頁
  155. /* function showThankyou() {
  156. axios.get('http://q.ptt.cx/coffee').then(res => {
  157. if(res.data.coffee == 1) {
  158. document.location = '/a1/index_complete_line.html';
  159. } else {
  160. document.location = '/a1/index_complete_line_after.html';
  161. }
  162. });
  163. // document.location = '/a1/index_complete_line.html';
  164. } */
  165. // 跳離頁面
  166. function show_input_text(checkbox_id, input_id) {
  167. var checkBox = document.getElementById(checkbox_id);
  168. var inp = document.getElementById(input_id);
  169. if (checkBox.checked == true){
  170. inp.style.display = "block";
  171. } else {
  172. inp.style.display = "none";
  173. }
  174. }
  175. function validate() {
  176. function q2_validate() {
  177. let phoneno = /^\d{10}$/;
  178. if( $('input[name="q2"]:visible').val() !== undefined && $('input[name="q2"]:visible').val().length <= 0) {
  179. $('input[name="q2"]:visible').addClass('error');
  180. if( !$('.error-text').length )
  181. $('input.error').after('<p class="error-text">請輸入正確手機號碼</p>');
  182. return false;
  183. } else if($('input[name="q2"]:visible').val() !== undefined && !phoneno.test($('input[name="q2"]:visible').val())){
  184. $('input[name="q2"]:visible').addClass('error');
  185. if( !$('.error-text').length )
  186. $('input.error').after('<p class="error-text">請輸入正確手機號碼</p>');
  187. return false;
  188. }else {
  189. $('input[name="q2"]:visible').removeClass('error');
  190. $('.error-text').remove();
  191. return true;
  192. }
  193. }
  194. function q3_validate() {
  195. 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,}))$/;
  196. if( $('input[name="q3"]:visible').val() !== undefined && $('input[name="q3"]:visible').val().length <= 0) {
  197. $('input[name="q3"]:visible').addClass('error');
  198. if( !$('.error-text').length )
  199. $('input.error').after('<p class="error-text">請輸入E-mail</p>');
  200. return false;
  201. } else if ( $('input[name="q3"]:visible').val() !== undefined && !emailPattern.test($('input[name="q3"]:visible').val()) ){
  202. $('input[name="q3"]:visible').addClass('error');
  203. if( !$('.error-text').length )
  204. $('input.error').after('<p class="error-text">請輸入正確email格式</p>');
  205. return false;
  206. }
  207. else {
  208. $('input[name="q3"]:visible').removeClass('error');
  209. $('.error-text').remove();
  210. return true;
  211. }
  212. }
  213. /* function q4_validate() {
  214. if( $('input[name="q4"]:visible').val() !== undefined && $('input[name="q4"]:visible').val().length <= 0 ) {
  215. $('input[name="q4"]:visible').addClass('error');
  216. if( !$('.error-text').length )
  217. $('input.error').after('<p class="error-text">請輸入建案名稱</p>');
  218. return false;
  219. }
  220. else {
  221. $('input[name="q4"]:visible').removeClass('error');
  222. $('.error-text').remove();
  223. return true;
  224. }
  225. } */
  226. return q2_validate() && q3_validate();
  227. }