goto.js 1.8 KB

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