들레아빠

상단 스크롤 버튼 업그레이드

33282748_1705816506.758.png33282748_1705816517.1135.png

 

/templates/taeho/base.html line 305~
[code]
  // 상단 스크롤 버튼
    $(function() {
        $("#top_btn").on("click", function() {
            $("html, body").animate({scrollTop:0}, '500');
            return false;
        });
    });

=>

  // 상단 스크롤 버튼
  jQuery(function($) {
    var $elem = $("html, body");
    var where = 0;
    $("#top_btn").on("click", function() {
      var windowHeight = $(document).height() - $(window).height();
      var winhalf = windowHeight * 0.5;

      if ($elem.scrollTop() < winhalf) {
        $elem.animate({ scrollTop: $elem.prop("scrollHeight") }, 400);
        where = 1;
      } else {
        $elem.animate({ scrollTop: 0 }, 400);
        where = 0;
      }
    });

    $(document).ready(function() {
      $(window).scroll(function() {
        var windowHeight = $(document).height() - $(window).height();
        var winhalf = windowHeight * 0.5;
        var scrollPos = $(document).scrollTop();
        var scrollPercent = (window.scrollY / (document.documentElement.scrollHeight - window.innerHeight)) * 100;
        var $buttonTop = $("#top_btn");

        if (scrollPos > winhalf) {
          $buttonTop.css({
            "border-color": "red",
            "line-height": "15px",
            "color": "red"
          }).html("<i class='fa fa-arrow-up' aria-hidden='true'></i>");
        } else {
          $buttonTop.css({
            "border-color": "blue",
            "line-height": "15px",
            "color": "blue"
          }).html("<i class='fa fa-arrow-down' aria-hidden='true'></i>");
        }
        if ($("#scroll_percentage").length === 0) {
          $("<p id=\'scroll_percentage\'></p>").appendTo($buttonTop);
        }
        $("#scroll_percentage").text(Math.round(scrollPercent));

      });
    });
  });
[/code]

|

댓글 2개

적용해보니 아주 잘 작동하네요. 감사합니다.

@sinbi님 감사 합니다.

댓글을 작성하시려면 로그인이 필요합니다.

그누보드6 팁자료실

그누보드6, 파이썬에 대한 팁과 자료를 올려주세요. 그누보드6 실서비스를 위한 웹서버 설정

+
제목 글쓴이 날짜 조회
2년 전 조회 1,353
2년 전 조회 1,205
2년 전 조회 1,436
2년 전 조회 1,091
2년 전 조회 963
2년 전 조회 1,213
2년 전 조회 883
2년 전 조회 1,319
2년 전 조회 835
2년 전 조회 688
2년 전 조회 1,175
2년 전 조회 1,249
2년 전 조회 821
2년 전 조회 1,297
2년 전 조회 946
2년 전 조회 1,899
2년 전 조회 781
2년 전 조회 1,210
2년 전 조회 1,510
2년 전 조회 1,097
2년 전 조회 1,440
2년 전 조회 1,294
2년 전 조회 1,454
2년 전 조회 1,038
2년 전 조회 2,162
2년 전 조회 1,963
2년 전 조회 1,212
2년 전 조회 710
2년 전 조회 906
2년 전 조회 2,511