# sliding menu

[browser](https://lochiwei.gitbook.io/web/browser) ⟩ [event](https://lochiwei.gitbook.io/web/browser/event) ⟩ [type](https://lochiwei.gitbook.io/web/browser/event/type) ⟩ [mouse](https://lochiwei.gitbook.io/web/browser/event/type/mouse) ⟩ [click](https://lochiwei.gitbook.io/web/browser/event/type/mouse/click) ⟩ example ⟩ sliding menu

{% hint style="success" %}
click to show/hide the dropdown menu.
{% endhint %}

{% tabs %}
{% tab title="💈範例" %}

* replit ⟩ [sliding menu](https://replit.com/@pegasusroe/sliding-menu#index.js) ,  require ⟩ [Node+ext](https://lochiwei.gitbook.io/web/browser/dom/type/node/+ext)

```javascript
// ⭐️ import
import { $ } from './js/ext/Node_ext.js';        // 👔 Node + ext
// ---------------------------------------------------------------

// elements
const menu = $('.menu');                // <div>
const menuTitle = $('.menu .title');    // <span>

// ⭐️ event handlers
// -------------------------------------------------------

menuTitle.onclick = () => {
    menu.classList.toggle('open');
};
```

📁 CSS

```css
/* -------- menu content -------- */
.menu ul {
    margin: 0;
    margin-left: 20px;
    padding-left: 20px;
    display: none;    /* closed */
    color: orange;
}

.menu.open ul {
  display: block;    /* open */
}

/* -------- menu title -------- */

/* <span> element */
.menu .title {
    cursor: pointer;
}

/* "::before" element */
.menu .title::before {
  content: '▶ ';    /* closed */
  font-size: 80%;
  color: green;
}

.menu.open .title::before {
  content: '▼ ';    /* open */
}
```

{% endtab %}

{% tab title="🗺️ 圖表" %}
{% embed url="<https://replit.com/@pegasusroe/sliding-menu#index.js>" %}
{% endtab %}

{% tab title="📗 參考" %}

* [ ] javascript.info ⟩ [Create a Sliding Menu](https://javascript.info/introduction-browser-events#create-a-sliding-menu)  ⭐️&#x20;
* [ ] Eloquent JS ⟩ [Ch. 15: Event Handling](https://eloquentjavascript.net/15_event.html) ⟩ [Mouse Clicks](https://eloquentjavascript.net/15_event.html#i_D5iwImkmyt)
  {% endtab %}

{% tab title="📘 手冊" %}

* [Event](https://developer.mozilla.org/en-US/docs/Web/API/Event) ⟩ [UIEvent](https://developer.mozilla.org/en-US/docs/Web/API/UIEvent) ⟩ [MouseEvent](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent) ⟩ [click event](https://developer.mozilla.org/en-US/docs/Web/API/Element/click_event)
* [elem.classList](https://developer.mozilla.org/en-US/docs/Web/API/Element/classList) - add, remove, toggle, replace CSS classes.
  {% endtab %}
  {% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://lochiwei.gitbook.io/web/browser/event/type/mouse/click/sliding-menu.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
