index.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. $(".gototop").hide();
  2. $(window).scroll(function () {
  3. var y = window.scrollY;
  4. if (y > 10) {
  5. $(".gototop").show();
  6. } else {
  7. $(".gototop").hide();
  8. }
  9. });
  10. $("*").each(function (index, element) {
  11. // 此元素被點選後執行
  12. $(this).click(function (e) {
  13. // 取得被點選元素的屬性:data-gt-target
  14. var target = $(this).attr("data-gt-target");
  15. var duration = $(this).attr("data-gt-duration");
  16. var offset = $(this).attr("data-gt-offset");
  17. // JS 語法:判斷式
  18. // if (條件) {程式區塊}
  19. // 當條件成立,會執行程式區塊
  20. // 如果 目標有資料 才會執行 { } 內的程式
  21. // 避免出現 undefine (未定義 - 不存在的資料)
  22. if (target) {
  23. //console.log("目標:" + target);
  24. //console.log("時間:" + duration);
  25. //console.log("位移:" + offset);
  26. // 上方位置 = 目標區塊.位移().上方位置
  27. var top = $(target).offset().top;
  28. //console.log("要前往元素的上方位置:" + top);
  29. // 網頁元素.停止().動畫({ 上方捲動:指定元素 - 位移},持續時間)
  30. // parseInt() 將文字轉為數字
  31. $("html").stop().animate({
  32. scrollTop: top - offset
  33. }, parseInt(duration));
  34. }
  35. });
  36. });
  37. // 避免動畫與使用者滾輪衝突
  38. // html 在滾動滾輪時 停止 html 所有效果
  39. $("html").on("mousewheel", function () {
  40. $("html").stop();
  41. });
  42. $(".playbutton").click(function () {
  43. var videosrc = $(this).data("info");
  44. $('.youtube-video').attr('src', `https://www.youtube.com/embed//${videosrc}?autoplay=1`);
  45. });
  46. $(".btn-close").click(function () {
  47. $('.youtube-video').attr('src', ``);
  48. });
  49. $('#yt-video').on('hidden.bs.modal', function () {
  50. $('.youtube-video').attr('src', ``);
  51. });
  52. $(".banner-slide").slick({
  53. dots: true,
  54. autoplay: true,
  55. arrows: false,
  56. slidesToShow: 1,
  57. slidesToScroll: 1,
  58. autoplaySpeed: 7000,
  59. initialSlide: 0,
  60. infinite: true,
  61. });
  62. $(".violetbeauty_sec01_slide").slick({
  63. slidesToShow: 4,
  64. slidesToScroll: 3,
  65. infinite: true,
  66. // centerMode: true,
  67. arrows: true,
  68. prevArrow: '<button type="button" class="slick-prev"><i class="fas fa-chevron-left" style="font-size: 32px;color: #CC7DB7;transform: translateY(-10px);"></i></button>',
  69. nextArrow: '<button type="button" class="slick-next"><i class="fas fa-chevron-right" style="font-size: 32px;color: #CC7DB7;transform: translateY(-10px);"></i></button>'
  70. });
  71. $(".violetbeauty_sec02_slide").slick({
  72. slidesToShow: 3,
  73. slidesToScroll: 3,
  74. infinite: true,
  75. // centerMode: true,
  76. arrows: true,
  77. prevArrow: '<button type="button" class="slick-prev"><i class="fas fa-chevron-left" style="font-size: 32px;color: #CC7DB7;transform: translateY(-10px);"></i></button>',
  78. nextArrow: '<button type="button" class="slick-next"><i class="fas fa-chevron-right" style="font-size: 32px;color: #CC7DB7;transform: translateY(-10px);"></i></button>'
  79. });
  80. $(".learn_more").click(function () {
  81. var courseid = $(this).data("info");
  82. // console.log(courseid);
  83. $.ajax({
  84. method: "GET",
  85. url: "coursecontent.json",
  86. dataType: "json",
  87. })
  88. .done(function (msg) {
  89. // console.log(msg)
  90. for (var i = 0; i < msg.length; i++) {
  91. if (msg[i].Courseid == courseid) {
  92. var CourseContent = '';
  93. console.log(msg[i]);
  94. CourseContent = `
  95. <div class="course_detail py-3">
  96. <div class="row">
  97. <div class="col-md-7">
  98. <div class="course_detail_img mt-3">
  99. <img class="img-fluid" src="${msg[i].CourseImg}" alt="">
  100. </div>
  101. </div>
  102. <div class="col-md-5">
  103. <div class="course_detail_text">
  104. <div class="features_title fw-bold text-start">${msg[i].CourseTitle}</div>
  105. <div class="sec_content_right_text">
  106. <p>${msg[i].Coursetext}</p>
  107. </div>
  108. </div>
  109. <div class="text-center">
  110. <button class="violetbeauty_CTA mt-4"><a style="text-decoration: none;"
  111. target="_blank" href="https://line.me/R/ti/p/%2540qlo9716l"><img
  112. class="cta_flower" src="./img/flower.png" alt="">立即體驗</a></button>
  113. </div>
  114. </div>
  115. </div>
  116. </div>
  117. `
  118. }
  119. $('.modal-body').html(CourseContent);
  120. }
  121. });
  122. });