goto.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // menu彈跳視窗
  2. $("#menu-box2").hide();
  3. $("#menu-box").hide();
  4. $("#menu-btn1").click(function () {
  5. $("#menu-box").fadeToggle("slow");
  6. $("#menu-box2").slideToggle( "slow" );
  7. });
  8. $(".feedback-slider1").slick({
  9. dots:true,
  10. dotsClass:'slick-dots',
  11. speed:1000,
  12. swipe:true,
  13. });
  14. $(".banner-slider").slick({
  15. dots:true,
  16. dotsClass:'slick-dots',
  17. speed:1000,
  18. swipe:true,
  19. });
  20. $( ".link" ).click(function() {
  21. $( "#menu-box2" ).fadeOut( "slow", function() {
  22. // Animation complete.
  23. });
  24. });
  25. $("*").each(function (index, element) {
  26. // 此元素被點選後執行
  27. $(this).click(function (e) {
  28. // 取得被點選元素的屬性:data-gt-target
  29. var target = $(this).attr("data-gt-target");
  30. var duration = $(this).attr("data-gt-duration");
  31. var offset = $(this).attr("data-gt-offset");
  32. // JS 語法:判斷式
  33. // if (條件) {程式區塊}
  34. // 當條件成立,會執行程式區塊
  35. // 如果 目標有資料 才會執行 { } 內的程式
  36. // 避免出現 undefine (未定義 - 不存在的資料)
  37. if (target) {
  38. //console.log("目標:" + target);
  39. //console.log("時間:" + duration);
  40. //console.log("位移:" + offset);
  41. // 上方位置 = 目標區塊.位移().上方位置
  42. var top = $(target).offset().top;
  43. //console.log("要前往元素的上方位置:" + top);
  44. // 網頁元素.停止().動畫({ 上方捲動:指定元素 - 位移},持續時間)
  45. // parseInt() 將文字轉為數字
  46. $("html").stop().animate({
  47. scrollTop: top - offset
  48. }, parseInt(duration));
  49. }
  50. });
  51. });
  52. // 避免動畫與使用者滾輪衝突
  53. // html 在滾動滾輪時 停止 html 所有效果
  54. $("html").on("mousewheel", function () {
  55. $("html").stop();
  56. });