Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 如何修复滚动定位单页响应菜单?_Jquery_Css - Fatal编程技术网

Jquery 如何修复滚动定位单页响应菜单?

Jquery 如何修复滚动定位单页响应菜单?,jquery,css,Jquery,Css,我创建了一个单页设计。所有的内容都在一个地方——主页。使用jqueryi代码创建定位导航。当滚动菜单的当前状态正在更新时,当单击链接时,它将滚动到该链接的正确位置/部分 不幸的是,该菜单在平板电脑和智能手机上效果不佳。 当我将视口更改为tablet时,它将滚动到该位置,但随后它将停止到早期,因此它不在浏览器顶部。在移动设备上,它将滚动到错误的位置,organizatie将始终是当前菜单项。是否解决此问题 // One Page Navigation - scroll to anchor id

我创建了一个单页设计。所有的内容都在一个地方——主页。使用jqueryi代码创建定位导航。当滚动菜单的当前状态正在更新时,当单击链接时,它将滚动到该链接的正确位置/部分

不幸的是,该菜单在平板电脑和智能手机上效果不佳。 当我将视口更改为tablet时,它将滚动到该位置,但随后它将停止到早期,因此它不在浏览器顶部。在移动设备上,它将滚动到错误的位置,
organizatie
将始终是当前菜单项。是否解决此问题

// One Page Navigation - scroll to anchor id
    $('#primary-navwrapper, #footer .list-of-links').find('li a[href^="#"]').click(function(event) { 
    //primary-navwrapper li:not(.prev-page, .next-page), .list-of-links li

        // Prevent from default action to intitiate
        event.preventDefault();

        // Update active class on click
        $('#primary-navwrapper li a').removeClass('current');
        $(this).addClass('current');

        // The id of the section we want to go to
        // var anchor = this.hash;
        var anchorId = $(this).attr('href');
        //console.log(anchorId);
        scrollToAnchor(anchorId);

        if (isMobile) {
            nav.slideToggle();
        } 

        return false;

    });


    function scrollToAnchor(anchorId) {

        // Our scroll target : the top position of the section that has the id referenced by our href
        if (anchorId.length) {
            var target = $(anchorId).offset().top - offset;
            //console.log("target" + target);
        }


        // The magic...smooth scrollin' goodness.
        $('html, body').animate({ scrollTop: target }, 500, function () {
            //window.location.hash = '!' + id;
            window.location.hash = anchorId;        
        });

    }

您可以现场查看。

您是否删除了上一个问题?为什么?我已经处理完你的最后一个问题了吗?为什么?我已经做完了