search
HomeWeb Front-endLayui TutorialHow to jump when clicking on layui sidebar

How to jump when clicking on layui sidebar

Apr 26, 2024 am 01:39 AM
layuiclick event

To implement click jump in the layui sidebar, you need to follow the following steps: define the jump path and specify the target path in the href attribute of the menu item. Add layui listening events, listen for menu item clicks, and jump to the specified path. Optionally, use the lay-nav-side sidebar navigation component, which automatically handles the click jump of navigation menu items.

How to jump when clicking on layui sidebar

How to implement click-to-jump in layui sidebar?

In the layui framework, the method to implement click-to-jump on the sidebar is as follows:

1. Define the jump target path

In the <a></a> tag of the sidebar menu, use the href attribute to specify the jump target path:

<ul class="layui-nav layui-nav-tree">
  <li class="layui-nav-item">
    <a href="index.html">
      <i class="layui-icon layui-icon-home"></i>
      <span>首页</span>
    </a>
  </li>
  <li class="layui-nav-item">
    <a href="about.html">
      <i class="layui-icon layui-icon-user"></i>
      <span>关于</span>
    </a>
  </li>
</ul>

2. Add layui listening events

After the page is loaded, listen to the click event of the sidebar menu item through layui's listening event:

layui.use('element', function() {
  var element = layui.element;

  // 监听侧边栏菜单项点击事件
  element.on('nav(lay-system-side-menu)', function(data) {
    var url = data.elem.getAttribute('href');
    // 执行页面跳转
    window.location.href = url;
  });
});

3. Use the layui sidebar navigation component

layui also provides a component specifically for sidebar navigation, lay-nav-side:

<div class="layui-side layui-bg-black">
  <div class="layui-side-scroll">
    <ul class="layui-nav lay-bg-black layui-nav-tree" lay-filter="lay-system-side-menu">
      <li class="layui-nav-item">
        <a href="index.html">
          <i class="layui-icon layui-icon-home"></i>
          <span>首页</span>
        </a>
      </li>
      <li class="layui-nav-item">
        <a href="about.html">
          <i class="layui-icon layui-icon-user"></i>
          <span>关于</span>
        </a>
      </li>
    </ul>
  </div>
</div>

is using lay-nav -side component, there is no need to manually listen for click events, layui will automatically handle the click jump of the navigation menu item.

The above is the detailed content of How to jump when clicking on layui sidebar. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use