-1

There is a strange error while using the fullpage script wheel event. When using the wheel event in the source, when section3 and section4 are reached, there is a problem that the contents shown in each section are displayed late. To return to the section when refreshing, history.pushState(null, null, "#" +currentSectionId); I used it, but it doesn't work well. Are there any errors in this source? help

function handleDisplaySize() {
var displayWidth = $(window).width();

        if (displayWidth >= 1281 && displayWidth < 1921) {
            $(window).on("wheel", wheelEventHandler);
        } else {
            $(window).off("wheel", wheelEventHandler);
            sessionStorage.removeItem("currentSectionPage");
            history.pushState(null, null, window.location.pathname);
        }
    }
    
    function wheelEventHandler(e) {
        // var lastPosTop = Number(4 * $(window).height()) - Number($(window).height());
        var lastPosTop = Number(4 * $(window).height()) - Number($(window).height() / 5);
        var scrollValue = $(document).scrollTop();
        if (mHtml.is(":animated")) return;
        if (e.originalEvent.deltaY > 0) {
            if (page == 5) return;
            page++;
        } else if (e.originalEvent.deltaY < 0) {
            if (page == 1) return;
            if(lastPosTop > scrollValue) page--;
            $("html, body").css("overflow", "hidden");
        }
        if (page == 5 && e.originalEvent.deltaY > 0) {
            var section5Top = $('#section5').offset().top - 100;
            $("html, body").animate({ scrollTop: section5Top }, 500);
        }
    
        var posTop = (page - 1) * $(window).height();
        //mHtml.animate({ scrollTop: posTop }, 500);
        //var scrollValue = $(document).scrollTop();
    
        if (page == 5) {
            $("html, body").css("overflow", "auto");
        }else{
            mHtml.animate({ scrollTop: posTop }, 500);
        }
    
        $(".section_one").each(function(index) {
            var offset = $(this).offset().top;
            var height = $(this).outerHeight();
            var top = $(document).scrollTop();
            var id = $(this).attr('id');
    
            if (top >= offset && top < offset + height) {
                $("#sidebar li").removeClass("active");
                $("#sidebar li:eq(" + index + ")").addClass("active");
                history.pushState(null, null, "#" + id);
                return false;
            }
        });
    
        updateActiveSection();
        var currentSectionId = $(".content_one .section_one").eq(page - 1).attr("id");
        sessionStorage.setItem("currentSectionPage", page);
        history.pushState(null, null, "#" + currentSectionId);
    
    }
    
    
    $("#sidebar a").on("click", function (e) {
        e.preventDefault();
        var targetSection = $(this).attr("href");
        var sectionTop = $(targetSection).offset().top;
        var isSection5 = targetSection === "#section5";
    
        $("html, body").css("overflow", isSection5 ? "auto" : "hidden");
    
        $("html, body").animate({ scrollTop: sectionTop }, 500, function() {
            if (!isSection5) {
                $("html, body").css("overflow", "hidden");
            }
            $(targetSection).siblings().removeAttr("tabindex");
            $(targetSection).attr("tabindex", 0);
            $(targetSection).focus();
        });
    
        page = $(targetSection).index() + 1;
        updateActiveSection();
        sessionStorage.setItem("currentSectionPage", page);
        history.pushState(null, null, targetSection);
    });
    
    $("#sidebar a").on("keydown", function (e) {
        if (e.key === "Enter") { // Enter 키
            e.preventDefault();
            var targetSection = $(this).attr("href");
            $(this).click();
        }
    });
    
    
    $(".section_one a , .section_one button").on("focus", function () {
        var parentSection = $(this).closest(".section_one");
        var sectionIndex = $(".section_one").index(parentSection);
        $("#sidebar li").removeClass("active");
        $("#sidebar li:eq(" + sectionIndex + ")").addClass("active");
        sessionStorage.setItem("currentSectionPage", sectionIndex + 1);
        page = sectionIndex + 1;
        var currentSectionId = parentSection.attr("id");
        history.pushState(null, null, "#" + currentSectionId);
    });
    
    
    
    function updateActiveSection() {
        $("#sidebar li").removeClass("active");
        $(".content_one .section_one").removeClass("onmove");
        $("#sidebar li").eq(page - 1).addClass("active");
        $(".content_one .section_one").eq(page - 1).addClass("onmove");
    }
    
    
    var mHtml = $("html");
    var page = 1;
    mHtml.animate({ scrollTop: 0 }, 10);
    $(window).resize(handleDisplaySize);
    
    handleDisplaySize();
    
    adjustSectionHeight();
    $(window).resize(adjustSectionHeight);
    var pageHeight = $(window).height();
    var savedPage = sessionStorage.getItem("currentSectionPage");
    if (savedPage) {
        page = parseInt(savedPage);
        var posTop = (page - 1) * $(window).height();
        mHtml.animate({ scrollTop: posTop }, 500);
        updateActiveSection();
    }
    function adjustSectionHeight() {
        var windowWidth = $(window).width();
        if (windowWidth >= 1281 && windowWidth < 1921) {
            var windowHeight = $(window).height();
            $('.section_one').css('height', windowHeight + 'px');
        } else {
            $('.section_one').css('height', 'auto');
        }
        $('#section5').css('height', 'auto');
    }
    
    $( '.search_btn button' ).click( function() {
        $( '.search_wrap' ).toggleClass( 'on' );
    } );
    
    $('.search_wrap .search_btn button').on('focusout', function() {
        $('.search_wrap').removeClass('on');
    });
    
    $('.search_wrap .keyword-btn button').on('focus', function() {
        $('.search_wrap').addClass('on');
    });
3
  • 1
    Please have a look at How to Ask. What exactly is not working? What are the errors you are receiving, please add these (as text) inside the question. Furthermore why is this question tagged with CSS? Please only tag with the appropriate tags
    – DarkBee
    Commented Jun 26 at 7:19
  • The current error is that when a wheel event occurs on the screen, the content on the screen appears late even after the wheel ends. Also, when refreshing, it takes too long to animate from the first header area to the corresponding area. It would be understandable if the image size of the content on the screen was large, but it seems that there was a problem with the source code in the script.
    – sh park
    Commented Jun 27 at 8:38
  • Please add all the details inside the question.
    – DarkBee
    Commented Jun 27 at 8:43

0

Browse other questions tagged or ask your own question.