goto.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. $(window).bind('scroll', function (e) {
  2. parallaxScroll();
  3. });
  4. function parallaxScroll() {
  5. var scrolled = $(window).scrollTop();
  6. $('#act1').css('top', (30 + (scrolled * .1)) + 'px');
  7. $('#act2').css('top', (800 - (scrolled * .2)) + 'px');
  8. $('#act3').css('top', (300 - (scrolled * .1)) + 'px');
  9. $('#act4').css('top', (0 + (scrolled * .1)) + 'px');
  10. $('#act5').css('top', (800 - (scrolled * .2)) + 'px');
  11. }
  12. // 手機課程大綱輪播
  13. $("#card-box").slick({
  14. arrows: false,
  15. slidesToShow: 1,
  16. centerMode: true,
  17. infinite: false,
  18. });
  19. // 手機課程大綱彈跳視窗
  20. // 視窗一
  21. $(".box-img01").click(function () {
  22. $(".mobile01-1").fadeIn();
  23. $(".mobile-box1").fadeIn();
  24. $(".card-box-1").slick({
  25. arrows: false,
  26. slidesToShow: 1,
  27. centerMode: true,
  28. infinite: false,
  29. });
  30. });
  31. $(".close").click(function () {
  32. $(".mobile-box1").fadeOut();
  33. $(".mobile01-1").fadeOut();
  34. });
  35. // 視窗二
  36. $(".mobile01-2").fadeOut(0);
  37. $(".mobile-box2").fadeOut(0);
  38. $(".box-img02").click(function() {
  39. $(".mobile01-2").fadeIn();
  40. $(".mobile-box2").fadeIn();
  41. $(".card-box-2").slick({
  42. arrows: false,
  43. slidesToShow: 1,
  44. centerMode: true,
  45. infinite: false,
  46. });
  47. });
  48. $(".close").click(function(){
  49. $(".mobile-box2").fadeOut();
  50. $(".mobile01-2").fadeOut();
  51. });
  52. // 視窗三
  53. $(".mobile01-3").fadeOut(0);
  54. $(".mobile-box3").fadeOut(0);
  55. $(".box-img03").click(function() {
  56. $(".mobile01-3").fadeIn();
  57. $(".mobile-box3").fadeIn();
  58. $(".card-box-3").slick({
  59. arrows: false,
  60. slidesToShow: 1,
  61. centerMode: true,
  62. infinite: false,
  63. });
  64. });
  65. $(".close").click(function(){
  66. $(".mobile-box3").fadeOut();
  67. $(".mobile01-3").fadeOut();
  68. });
  69. // 手機課程日程輪播
  70. $("#card-box2").slick({
  71. arrows: false,
  72. slidesToShow: 1,
  73. centerMode: true,
  74. infinite: false,
  75. });
  76. // 手機選單彈跳視窗
  77. $("#menu-box2").hide();
  78. $("#menu-box").hide();
  79. $("#menu-btn1").click(function () {
  80. $("#menu-box").slideToggle("slow");
  81. $("#menu-box2").slideToggle("slow");
  82. });
  83. $(".link").click(function () {
  84. $("#menu-box").slideUp("slow", function () {
  85. $("#menu-box2").slideUp("slow");
  86. // Animation complete.
  87. });
  88. });
  89. $("*").each(function (index, element) {
  90. // 此元素被點選後執行
  91. $(this).click(function (e) {
  92. // 取得被點選元素的屬性:data-gt-target
  93. var target = $(this).attr("data-gt-target");
  94. var duration = $(this).attr("data-gt-duration");
  95. var offset = $(this).attr("data-gt-offset");
  96. // JS 語法:判斷式
  97. // if (條件) {程式區塊}
  98. // 當條件成立,會執行程式區塊
  99. // 如果 目標有資料 才會執行 { } 內的程式
  100. // 避免出現 undefine (未定義 - 不存在的資料)
  101. if (target) {
  102. //console.log("目標:" + target);
  103. //console.log("時間:" + duration);
  104. //console.log("位移:" + offset);
  105. // 上方位置 = 目標區塊.位移().上方位置
  106. var top = $(target).offset().top;
  107. //console.log("要前往元素的上方位置:" + top);
  108. // 網頁元素.停止().動畫({ 上方捲動:指定元素 - 位移},持續時間)
  109. // parseInt() 將文字轉為數字
  110. $("html").stop().animate({
  111. scrollTop: top - offset
  112. }, parseInt(duration));
  113. }
  114. });
  115. });
  116. // 避免動畫與使用者滾輪衝突
  117. // html 在滾動滾輪時 停止 html 所有效果
  118. $("html").on("mousewheel", function () {
  119. $("html").stop();
  120. });
  121. $(".arrow").hide();
  122. $(window).scroll(function () {
  123. var y = window.scrollY;
  124. if (y > 10) {
  125. $(".arrow").show();
  126. } else {
  127. $(".arrow").hide();
  128. }
  129. });