goto.js 4.9 KB

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