goto.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. $('designer-nav').hide();
  2. $(".item-down").click(function () {
  3. $('.designer-nav').slideToggle();
  4. });
  5. // var scene = document.getElementById('scene');
  6. // var parallaxInstance = new Parallax(scene);
  7. $("*").each(function (index, element) {
  8. // 此元素被點選後執行
  9. $(this).click(function (e) {
  10. // 取得被點選元素的屬性:data-gt-target
  11. var target = $(this).attr("data-gt-target");
  12. var duration = $(this).attr("data-gt-duration");
  13. var offset = $(this).attr("data-gt-offset");
  14. // JS 語法:判斷式
  15. // if (條件) {程式區塊}
  16. // 當條件成立,會執行程式區塊
  17. // 如果 目標有資料 才會執行 { } 內的程式
  18. // 避免出現 undefine (未定義 - 不存在的資料)
  19. if (target) {
  20. //console.log("目標:" + target);
  21. //console.log("時間:" + duration);
  22. //console.log("位移:" + offset);
  23. // 上方位置 = 目標區塊.位移().上方位置
  24. var top = $(target).offset().top;
  25. //console.log("要前往元素的上方位置:" + top);
  26. // 網頁元素.停止().動畫({ 上方捲動:指定元素 - 位移},持續時間)
  27. // parseInt() 將文字轉為數字
  28. $("html").stop().animate({
  29. scrollTop: top - offset
  30. }, parseInt(duration));
  31. }
  32. });
  33. });
  34. // 避免動畫與使用者滾輪衝突
  35. // html 在滾動滾輪時 停止 html 所有效果
  36. $("html").on("mousewheel", function () {
  37. $("html").stop();
  38. });
  39. // 手機選單彈跳視窗
  40. $("#menu-box2").hide();
  41. $("#menu-box").hide();
  42. $("#menu-btn1").click(function () {
  43. $("#menu-box").fadeToggle("slow");
  44. $("#menu-box2").fadeToggle("slow");
  45. });
  46. $(".link").click(function () {
  47. $("#menu-box").slideUp("slow", function () {
  48. $("#menu-box2").slideUp("slow");
  49. // Animation complete.
  50. });
  51. });
  52. // 文字動畫
  53. const sec = document.querySelectorAll('.sec');
  54. console.log(sec.length);
  55. const title = document.querySelectorAll('.title');
  56. const cover = document.querySelectorAll('.cover');
  57. const test_content = document.querySelectorAll('.test_content');
  58. function checkSlide() {
  59. console.log('pass');
  60. sec.forEach((block, i) => {
  61. // half way through the image
  62. //const test = document.querySelector('.test');
  63. const slideInAt = window.scrollY + window.innerHeight;
  64. console.log(slideInAt);
  65. //console.log(test.offsetTop);
  66. // bottom of the image
  67. const isHalfShown = slideInAt > block.offsetTop;
  68. if (isHalfShown) {
  69. console.log('active');
  70. title[i].style.bottom = '0em';
  71. //document.querySelector('.title').style.bottom = '0em';
  72. test_content[i].classList.add('fadein');
  73. cover[i].classList.add('slidein');
  74. //test.firstElementChild.classList.add('fadein');
  75. //test_content[i].fadeIn(1500);
  76. // $('.test_content').fadeIn(1500);
  77. }
  78. })
  79. };
  80. window.addEventListener('scroll', checkSlide);
  81. window.addEventListener('scroll', sec03PlantImg);
  82. window.addEventListener('scroll', sec03BottomImg);
  83. console.log(document.querySelector('.sec03-big').offsetTop);
  84. function sec03PlantImg() {
  85. const slideInAt = window.scrollY + window.innerHeight;
  86. const toTop = document.querySelector('.sec03-big').offsetTop + document.querySelector('.sec03_plant').offsetTop;
  87. const isHalfShown = slideInAt > toTop ;
  88. console.log(toTop);
  89. if (isHalfShown) {
  90. document.querySelector('.sec03_plant .p_cover').classList.add('slidein');
  91. }
  92. };
  93. function sec03BottomImg() {
  94. const slideInAt = window.scrollY + window.innerHeight;
  95. const toTop = document.querySelector('.sec03-big').offsetTop + document.querySelector('.sec_bottom').offsetTop + 300;
  96. const isHalfShown = slideInAt > toTop ;
  97. console.log(toTop);
  98. if (isHalfShown) {
  99. document.querySelector('.sec_bottom .b_cover').classList.add('slidein');
  100. }
  101. };
  102. // var flagX = 0;
  103. // var flagXM = 0;
  104. // function getFlag(){
  105. // flagX = event.touches[0].pageX;
  106. // flagXM = flagX;
  107. // }
  108. // function setFlag(){
  109. // flagXM = event.touches[0].pageX;
  110. // }
  111. // function change(){
  112. // var range = flagXM - flagX;
  113. // //如果水平滑動距離小於30,就不切換
  114. // if(Math.abs(range) < 30){
  115. // return false;
  116. // }
  117. // var direction = range < 0 ?'next':'prev';
  118. // $("#carousel-example-generic").carousel(direction);
  119. // }