Dropdown Menu With Folding/Unfolding Effects | Folding Paper Menu

Folding Paper Menu to create a dropdown menu that allows the user to reveal menu items with collapsible effects just as they would on a piece of paper.

How to make use of it:

1. Load the newest jQuery library and Bootstrap’s stylesheet.

<link rel="stylesheet" href="/path/to/cdn/bootstrap.min.css" />
<script src="/path/to/cdn/jquery.min.js"></script>

2. Create a dropdown menu for Bootstrap’s checklist group part as follows:

<ul class="list-group position-relative" id="folding">
  <li class="list-group-item d-flex align-items-center">
    <img class="mr-4" src="https://picsum.photos/100?random=1"/>
    <div>
      <h2>Lorem Ipsum 1</h2>
      <p>Dolor sit amet</p>
    </div>
  </li>
  <li class="list-group-item d-flex align-items-center">
    <img class="mr-4" src="https://picsum.photos/100?random=2"/>
    <div>
      <h2>Lorem Ipsum 2</h2>
      <p>Dolor sit amet</p>
    </div>
  </li>
  <li class="list-group-item d-flex align-items-center">
    <img class="mr-4" src="https://picsum.photos/100?random=3"/>
    <div>
      <h2>Lorem Ipsum 3</h2>
      <p>Dolor sit amet</p>
    </div>
  </li>
  ... more list items here ...
  <li class="list-group-item navbar-light text-center"><span class="navbar-toggler-icon"></span></li>
</ul>

3. The required CSS types for the menu objects.

.list-group li {
  position: absolute;
  left: 0px;
  right: 0px;
  zoom: 1;
  transform-origin: 50% 100%;
  transform: perspective(1000px) rotate3d(1, 0, 0, 90deg);
}

.list-group li:nth-child(even) {
  transform-origin: 50% 0%;
  background: #eee;
}

.list-group li:last-child {
  transform: none;
  cursor: pointer;
}

4. The principal JavaScript/jQuery to allow the folding dropdown menu.

const foldingMenu = $("#foldingMenu"),
  toggler = $("li:last-child", foldingMenu),
  steps = 10,
  animationTime = 400,
  perspective = 1000,
  degree = 90,
  classNames = {
    animatingUp: "animating-up",
    animatingDown: "animating-down",
    unfolded: "unfolded",
    folded: "folded"
  };
(() =>
 foldingMenu.each(() => {
  const evenChild = foldingMenu.children(":even").not(toggler),
        oddChild = foldingMenu.children(":odd").not(toggler),
        listItems = $('li', foldingMenu),
        firstItemHeight = $('li', foldingMenu).eq(0).outerHeight(),
        degreePerStep = degree / steps;
  let counter = 0;

  changeStatus = (callBack) => {
    (applyTransform = () => {
      let angle = 90 - (foldingMenu.hasClass(classNames.unfolded) ? --counter : ++counter) * degreePerStep,
          currentHeight = 0,
          itemTop = 0;
      evenChild.css("transform", `perspective(${perspective}px) rotate3d(1, 0, 0, -${angle}deg)`);
      oddChild.css("transform", `perspective(${perspective}px) rotate3d(1, 0, 0,${angle}deg)`);
      currentHeight = (counter >= 0) ? parseInt(listItems[0].getBoundingClientRect().height) : 0;
      for (let i = 0; i < listItems.length; i++) {
        itemTop = (1 === i % 2) ? currentHeight * (i + 1) - firstItemHeight : currentHeight * i;
        listItems[i].style.top = itemTop + "px";
      }
      (counter === steps || 0 === counter) ? callBack() : setTimeout(applyTransform, animationTime / steps);
    })();
  };
  toggler.on("click", e => {
    foldingMenu.hasClass(classNames.animatingUp) ||
      (foldingMenu.hasClass(classNames.unfolded) ? (foldingMenu.addClass(classNames.animatingUp),
          changeStatus(() => foldingMenu.removeClass(`${classNames.animatingUp} ${classNames.unfolded}`))
         )
       : (foldingMenu.addClass(classNames.animatingUp, classNames.animatingDown),
          changeStatus(() => {
      foldingMenu.removeClass(`${classNames.animatingUp} ${classNames.animatingDown}`);
      foldingMenu.addClass(classNames.unfolded);
    })));
    e.preventDefault();
  });
})
)(jQuery);

See Demo And Download

Official Website(housamz): Click Here

This superior jQuery/javascript plugin is developed by housamz . For extra Advanced Usage, please go to the official website.

Related Posts

HStack-and-VStack-in-CSS

CSS Layout Components Horizontal/Vertical Stack | HStack and VStack

HStack and VStack in CSS – CSS layout components that (basically) stack anything horizontally and vertically. A pure CSS library that makes it easy to stack elements…

Floating-Whatsapp-Chat-Button

How to Add Floating Whatsapp Chat Button In HTML | venom-button

Venom Button is a very simple plugin for the jQuery floating WhatsApp button. Adds a floating button to your site that calls WhatsApp Click to Chat API. It will automatically start the WhatsApp…

Data-Table-Generator-Tabulator

Interactive Data Table Generator with JS/jQuery and JSON | Tabulator

Tabulator allows you to create interactive tables in seconds from any HTML Table, JavaScript array, AJAX data source, or JSON format data. Just include the library in your…

alert-confirm-prompt-attention-js

Simple Alert, Confirm, Prompt Popup Using Vanilla JavaScript Library | attention.js

JavaScript provides various built-in functionality to display popup messages for different purposes. Attention JS is a vanillaJS plugin used to create a custom alert, confirm, or Prompt…

Bootstrap-4-Sidebar-Menu-Responsive-Template

Bootstrap 4 Sidebar Menu Responsive Template | MDB

Bootstrap Side Navbar – Responsive sidebar template based on the Bootstrap 4 framework. An easy-to-use, totally responsive, Google Material Design impressed aspect navigation for modern web app…

Bootstrap-4-Toast-Notification-Plugin

Lightweight Bootstrap 4 Toast Notification Plugin | BS4 Advanced Toast

A lightweight Bootstrap 4 Toast Notification plugin integrated with JS/jQuery. bs4-toast.js is a JavaScript library that enhances the native Bootstrap toast component with icons, buttons, callbacks, and…

Leave a Reply

Your email address will not be published. Required fields are marked *