scripts.js 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. function getParameterByName(name, url = window.location.href) {
  2. name = name.replace(/[\[\]]/g, '\\$&');
  3. var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),
  4. results = regex.exec(url);
  5. if (!results) return null;
  6. if (!results[2]) return '';
  7. return decodeURIComponent(results[2].replace(/\+/g, ' '));
  8. }
  9. function getSource() {
  10. let id = getParameterByName('utm_source');
  11. $('#utm_source').val(id);
  12. console.log(id);
  13. }
  14. getSource();
  15. $('.owl-carousel-pc').owlCarousel({
  16. loop: true,
  17. margin: 0,
  18. nav:true,
  19. autoWidth:true,
  20. mouseDrag: true,
  21. touchDrag: true,
  22. smartSpeed: 1000,
  23. autoplay: true,
  24. autoplayTimeout: 9000,
  25. autoplayHoverPause: false,
  26. responsive:{
  27. 0:{
  28. items:1
  29. },
  30. 600:{
  31. items:1
  32. },
  33. 1200:{
  34. items:2
  35. }
  36. }
  37. });
  38. $('.owl-carousel-mb').owlCarousel({
  39. loop:true,
  40. margin: 0,
  41. nav:true,
  42. mouseDrag: true,
  43. touchDrag: true,
  44. smartSpeed: 0,
  45. autoplay: true,
  46. autoplayTimeout: 10000,
  47. autoplayHoverPause: false,
  48. responsive:{
  49. 0:{
  50. items:1
  51. },
  52. 600:{
  53. items:1
  54. },
  55. 1000:{
  56. items:2
  57. }
  58. }
  59. });
  60. $('.owl-carousel-mb2').owlCarousel({
  61. loop:true,
  62. margin: 0,
  63. nav:true,
  64. mouseDrag: true,
  65. touchDrag: true,
  66. smartSpeed: 0,
  67. autoplay: true,
  68. autoplayTimeout: 10000,
  69. autoplayHoverPause: false,
  70. responsive:{
  71. 0:{
  72. items:1
  73. },
  74. 600:{
  75. items:1
  76. },
  77. 1000:{
  78. items:2
  79. }
  80. }
  81. });
  82. $('.owl-carousel-mb3').owlCarousel({
  83. loop:true,
  84. margin: 0,
  85. nav:true,
  86. mouseDrag: true,
  87. touchDrag: true,
  88. smartSpeed: 0,
  89. autoplay: true,
  90. autoplayTimeout: 10000,
  91. autoplayHoverPause: false,
  92. responsive:{
  93. 0:{
  94. items:1
  95. },
  96. 600:{
  97. items:1
  98. },
  99. 1000:{
  100. items:2
  101. }
  102. }
  103. });
  104. $('#ph1 .nav-item').on('click', function(e) {
  105. $('.owl-carousel-mb2').trigger('to.owl.carousel', 0)
  106. })
  107. $('#ph1 .nav-item').on('click', function(e) {
  108. $('.owl-carousel-mb3').trigger('to.owl.carousel', 0)
  109. })
  110. $('.owl-nav').css('display', 'none');
  111. $('designers__card').click(function(e){
  112. console.log(e);
  113. let url = e.target.dataset.address;
  114. document.location = url;
  115. })
  116. //jQuery time
  117. var current_fs, next_fs, previous_fs; //fieldsets
  118. var left, opacity, scale; //fieldset properties which we will animate
  119. var animating; //flag to prevent quick multi-click glitches
  120. $(".next").click(function(){
  121. if( !validate() ){
  122. return false;
  123. }
  124. if(animating) return false;
  125. animating = true;
  126. $("html,body").animate(
  127. {
  128. scrollTop: $(".personal__box").offset().top
  129. },
  130. 0
  131. );
  132. current_fs = $(this).parent();
  133. next_fs = $(this).parent().next();
  134. //activate next step on progressbar using the index of next_fs
  135. $("#progressbar li").eq($("fieldset").index(next_fs)).addClass("active");
  136. //show the next fieldset
  137. next_fs.show();
  138. //hide the current fieldset with style
  139. current_fs.animate({opacity: 0}, {
  140. step: function(now, mx) {
  141. //as the opacity of current_fs reduces to 0 - stored in "now"
  142. //1. scale current_fs down to 80%
  143. scale = 1 - (1 - now) * 0.2;
  144. //2. bring next_fs from the right(50%)
  145. left = (now * 50)+"%";
  146. //3. increase opacity of next_fs to 1 as it moves in
  147. opacity = 1 - now;
  148. current_fs.css({
  149. 'transform': 'scale('+scale+')',
  150. 'position': 'absolute'
  151. });
  152. next_fs.css({'left': left, 'opacity': opacity});
  153. },
  154. duration: 800,
  155. complete: function(){
  156. current_fs.hide();
  157. animating = false;
  158. },
  159. //this comes from the custom easing plugin
  160. easing: 'easeInOutBack'
  161. });
  162. });
  163. $(".previous").click(function(){
  164. if(animating) return false;
  165. animating = true;
  166. $("html,body").animate(
  167. {
  168. scrollTop: $(".personal__box").offset().top
  169. },
  170. 0
  171. );
  172. current_fs = $(this).parent();
  173. previous_fs = $(this).parent().prev();
  174. //de-activate current step on progressbar
  175. $("#progressbar li").eq($("fieldset").index(current_fs)).removeClass("active");
  176. //show the previous fieldset
  177. previous_fs.show();
  178. //hide the current fieldset with style
  179. current_fs.animate({opacity: 0}, {
  180. step: function(now, mx) {
  181. //as the opacity of current_fs reduces to 0 - stored in "now"
  182. //1. scale previous_fs from 80% to 100%
  183. scale = 0.8 + (1 - now) * 0.2;
  184. //2. take current_fs to the right(50%) - from 0%
  185. left = ((1-now) * 50)+"%";
  186. //3. increase opacity of previous_fs to 1 as it moves in
  187. opacity = 1 - now;
  188. current_fs.css({'left': left});
  189. previous_fs.css({'transform': 'scale('+scale+')', 'opacity': opacity});
  190. },
  191. duration: 800,
  192. complete: function(){
  193. current_fs.hide();
  194. animating = false;
  195. },
  196. //this comes from the custom easing plugin
  197. easing: 'easeInOutBack'
  198. });
  199. });
  200. function reload() {
  201. console.log("pass");
  202. location.reload();
  203. }
  204. $("input[name=submit]").click(function(){
  205. let stop;
  206. console.log($("#msform").serialize());
  207. if( $('input[name="q9"]:visible').val() !== undefined && !$('input[name="q9"]:visible').prop('checked') ) {
  208. stop = 1;
  209. $('#term-error').text('必須同意免責聲明與隱私使用政策');
  210. }else {
  211. stop = 0;
  212. $('#term-error').text('');
  213. }
  214. if(stop == 0) {
  215. alert("我們已將價值5萬元裝修折價券寄至您所填寫的電子信箱,請確認是否收到,謝謝!");
  216. }
  217. });
  218. // 依據管道導頁
  219. /* function showThankyou() {
  220. axios.get('http://q.ptt.cx/coffee').then(res => {
  221. if(res.data.coffee == 1) {
  222. document.location = '/a1/index_complete_line.html';
  223. } else {
  224. document.location = '/a1/index_complete_line_after.html';
  225. }
  226. });
  227. // document.location = '/a1/index_complete_line.html';
  228. } */
  229. // 跳離頁面
  230. function show_input_text(checkbox_id, input_id) {
  231. var checkBox = document.getElementById(checkbox_id);
  232. var inp = document.getElementById(input_id);
  233. if (checkBox.checked == true){
  234. inp.style.display = "block";
  235. } else {
  236. inp.style.display = "none";
  237. }
  238. }
  239. function validate() {
  240. function q2_validate() {
  241. let phoneno = /^\d{10}$/;
  242. if( $('input[name="q2"]:visible').val() !== undefined && $('input[name="q2"]:visible').val().length <= 0) {
  243. $('input[name="q2"]:visible').addClass('error');
  244. if( !$('.error-text').length )
  245. $('input.error').after('<p class="error-text">請輸入正確手機號碼</p>');
  246. return false;
  247. } else if($('input[name="q2"]:visible').val() !== undefined && !phoneno.test($('input[name="q2"]:visible').val())){
  248. $('input[name="q2"]:visible').addClass('error');
  249. if( !$('.error-text').length )
  250. $('input.error').after('<p class="error-text">請輸入正確手機號碼</p>');
  251. return false;
  252. }else {
  253. $('input[name="q2"]:visible').removeClass('error');
  254. $('.error-text').remove();
  255. return true;
  256. }
  257. }
  258. function q3_validate() {
  259. 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,}))$/;
  260. if( $('input[name="q3"]:visible').val() !== undefined && $('input[name="q3"]:visible').val().length <= 0) {
  261. $('input[name="q3"]:visible').addClass('error');
  262. if( !$('.error-text').length )
  263. $('input.error').after('<p class="error-text">請輸入E-mail</p>');
  264. return false;
  265. } else if ( $('input[name="q3"]:visible').val() !== undefined && !emailPattern.test($('input[name="q3"]:visible').val()) ){
  266. $('input[name="q3"]:visible').addClass('error');
  267. if( !$('.error-text').length )
  268. $('input.error').after('<p class="error-text">請輸入正確email格式</p>');
  269. return false;
  270. }
  271. else {
  272. $('input[name="q3"]:visible').removeClass('error');
  273. $('.error-text').remove();
  274. return true;
  275. }
  276. }
  277. /* function q4_validate() {
  278. if( $('input[name="q4"]:visible').val() !== undefined && $('input[name="q4"]:visible').val().length <= 0 ) {
  279. $('input[name="q4"]:visible').addClass('error');
  280. if( !$('.error-text').length )
  281. $('input.error').after('<p class="error-text">請輸入建案名稱</p>');
  282. return false;
  283. }
  284. else {
  285. $('input[name="q4"]:visible').removeClass('error');
  286. $('.error-text').remove();
  287. return true;
  288. }
  289. } */
  290. return q2_validate() && q3_validate();
  291. }
  292. /* function getJson() {
  293. $.getJSON("js/json.txt", function(data){
  294. data.forEach((item, idx) => {
  295. console.log(item);
  296. })
  297. })
  298. }
  299. getJson(); */