简体   繁体   English

自动滚动页面+关闭侧边栏菜单项选择后+链接菜单项与部分ID(Wordpress - Jquery)

[英]Auto Scroll Page + Close Sidebar After menu item select + Link Menu item with Section Ids(Wordpress - Jquery)

I am trying to create a custom sidebar menu...I have one page site with section on it...Every sidebar menu link should be connected to a specific section.I have created the menu but have two problems:我正在尝试创建一个自定义侧边栏菜单...我有一个带有部分的页面网站...每个侧边栏菜单链接都应连接到特定部分。我已经创建了菜单但有两个问题:

1) I want to link the menu items with sections ids with the help of jquery. 1) 我想在 jquery 的帮助下将菜单项与部分 id 链接起来。 2) When user click on the menu item inthe sidebar,it should be closed automatically and scroll the page to that section. 2)当用户点击侧边栏中的菜单项时,它应该自动关闭并将页面滚动到该部分。

I am new to Jquery and wordpress..Please help me to resolve this issue.我是 Jquery 和 wordpress 的新手。请帮我解决这个问题。

Sidebar Html:侧边栏 Html:

<ul id="primary-menu" class="main-nav" role="menu">
    <li class="menu-item menu-item-type-custom menu-item-object-custom">
        <a href="#quote" data-level="1">
            <span class="menu-item-text">
                <span class="menu-text">Instant Quote</span>
                <i class="underline"></i>
            </span>
        </a>
    </li> 
    <li class="menu-item menu-item-type-custom menu-item-object-custom">
        <a href="#ethos" data-level="1">
            <span class="menu-item-text">
                <span class="menu-text">Ethos</span>
                <i class="underline"></i>
            </span>
        </a>
    </li>             
</ul>

Here is my Sidebar:这是我的侧边栏:

在此处输入图像描述

You have to give your section specific id like <section id="quote">你必须给你的部分特定的 id,比如<section id="quote">

Then in your main.js write something然后在你的 main.js 中写一些东西

$('.menu-item').find('a').click(function(){
        var $href = $(this).attr('href');
        var $anchor = $($href).offset();
        $('body, html').animate({ scrollTop: $anchor.top} ,1500);
        return false;
    });

For Closing the sidebar It depends on how you made this sidebar.对于关闭侧边栏这取决于你如何制作这个侧边栏。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM