国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Table of Contents
Switch switch
Transition effect
A little JavaScript
Home Web Front-end CSS Tutorial Menu Reveal By Page Rotate Animation

Menu Reveal By Page Rotate Animation

Apr 02, 2025 pm 01:47 PM

Menu Reveal By Page Rotate Animation

The website menu design methods are diverse. Some menus are always visible and all options are displayed directly; others are hidden and need to be clicked to expand. The way the hidden menus are expanded is different: some slide out and cover content, some push the content away, and some use full screen display.

Each method has its advantages and disadvantages, and the best choice depends on the specific application scenario. I personally prefer the slide-out menu, and certainly not all situations apply. But if a space-saving and easy-to-access menu is needed, the slide-out menu is hard to surpass.

However, slide-out menus often conflict with page content. It will at least block the content, and at worst it will remove the content completely from the UI.

I tried a different approach that combines the durability and usability of a fixed location menu, as well as the space-saving hidden slide-out menu without removing the user from the current content.

Here is my implementation method.

Switch switch

We are building a menu with two states (on and close) and switching between the two. This is where the checkbox trick comes into play. It's perfect because the checkbox has two common interactive states—checked and unchecked (and uncertain states)—that can be used to trigger those states.

The check box is hidden under the menu icon and is positioned using CSS so it cannot be seen even if the user interacts with it. Selecting the check box (or, ahem , menu icon) will display the menu. Uncheck hides it. It's that simple. We don't even need JavaScript to do the job!

Of course, checkbox tricks aren't the only way, and if you want to switch classes using JavaScript to open and close menus, that's totally OK.

Importantly, the checkbox should be ahead of the main content in the source code, because we will eventually write the :checked selector that requires the sibling selector. If this causes layout issues, use Grid or Flexbox for layouts, as they have nothing to do with source code order, like how I can take advantage of its advantages for CSS counting.

Use appearance CSS property to remove the default style of the checkbox (added by the browser), and then add a pseudo-element with a menu icon so that the user cannot see the checkbox blocks.

First, the basic tags:

<input type="checkbox" id="menu-toggle">
<div id="page">
  <!-- Page content-->
</div>
<div id="menu">
  <!-- Menu content-->
</div>

And basic CSS for checkbox tricks and menu icons:

 /* Hide the checkbox and reset the style*/
input[type="checkbox"] {
  appearance: initial; /* Delete box*/
  border: 0; margin: 0; outline: none; /* Remove default margins, borders and outlines*/
  width: 30px; height: 30px; /* Set menu icon size*/
  z-index: 1; /* Make sure it is on top*/
}

/* Menu icon*/
input::after {
  content: "\2255";
  display: block;
  font: 25pt/30px "georgia";
  text-indent: 10px;
  width: 100%; height: 100%;
}

/* Page content container*/
#page {
  background: url("earbuds.jpg") #ebebeb center/cover;
  width: 100%; height: 100%;
}

I also added the style of #page content, which will be a full-size background image.

Transition effect

Two things happen when you click on a menu control. First, the menu icon is changed to the "×" mark, indicating that you can click it to close the menu. Therefore, when the input is in the :checked state, we select the ::after pseudo-element entered in the checkbox:

 input:checked::after {
  content: "\00d7"; /* Change to "×" tag*/
  color: #ebebeb;
}

Second, the main content (our "headphones" image) is converted to display the menu below. It moves right, rotates and shrinks, and its left corner becomes an angle. This is to make the content look like it is being pushed back, like an open door.

 input:checked ~ #page {
  clip-path: polygon(0 8%, 100% 0, 100% 100%, 0 92%);
  transform: translateX(40%) rotateY(10deg) scale(0.8);
  transform-origin: right center;
  transition: all .3s linear;
}

I use clip-path to change the angle of the image.

Since we are applying transitions to the transformation, #page requires an initial clip-path value so that there is something to make the transition. We will also add a transition on #page as it will allow it to close smoothly as it opens.

 #page {
  background: url("earbuds.jpeg") #ebebeb center/cover;
  clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%);
  transition: all .3s linear;
  width: 100%; height: 100%;
}

We basically completed the core design and code. When the check box is unchecked (by clicking the "×" mark), the conversion on the headset image will be automatically undoed and it will be taken back to the center position.

A little JavaScript

Even if we already have what we want, there is one more thing to improve the user experience: close the menu when clicking (or clicking) #page element. This way, the user can return the content without looking up or even using the "×" tag.

Since this is just another way to hide the menu, we can use JavaScript. What if JavaScript is disabled for some reason? It doesn't matter. It's just an enhancement that won't prevent the menu from working without it.

 document.querySelector("#page").addEventListener('click', (e, checkbox = document.querySelector('input')) => {
  if (checkbox.checked) { checkbox.checked = false; e.stopPropagation(); }
});

The purpose of these three lines of code is to add a click event handler to #page element. If the checkbox is in the :checked state, uncheck the checkbox to close the menu.

We've been looking at the demos made for vertical/vertical designs, but it works just as well at large screen sizes depending on what we're using.

This is just one way or try to a typical slide-out menu. Animation opens up a lot of possibilities, and you may also have dozens of other ideas. In fact, I would love to hear (or better yet, see) them, so please share!

The above is the detailed content of Menu Reveal By Page Rotate Animation. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
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

Undress AI Tool

Undress AI Tool

Undress images for free

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.

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

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What is 'render-blocking CSS'? What is 'render-blocking CSS'? Jun 24, 2025 am 12:42 AM

CSS blocks page rendering because browsers view inline and external CSS as key resources by default, especially with imported stylesheets, header large amounts of inline CSS, and unoptimized media query styles. 1. Extract critical CSS and embed it into HTML; 2. Delay loading non-critical CSS through JavaScript; 3. Use media attributes to optimize loading such as print styles; 4. Compress and merge CSS to reduce requests. It is recommended to use tools to extract key CSS, combine rel="preload" asynchronous loading, and use media delayed loading reasonably to avoid excessive splitting and complex script control.

External vs. Internal CSS: What's the Best Approach? External vs. Internal CSS: What's the Best Approach? Jun 20, 2025 am 12:45 AM

ThebestapproachforCSSdependsontheproject'sspecificneeds.Forlargerprojects,externalCSSisbetterduetomaintainabilityandreusability;forsmallerprojectsorsingle-pageapplications,internalCSSmightbemoresuitable.It'scrucialtobalanceprojectsize,performanceneed

Does my CSS must be on lower case? Does my CSS must be on lower case? Jun 19, 2025 am 12:29 AM

No,CSSdoesnothavetobeinlowercase.However,usinglowercaseisrecommendedfor:1)Consistencyandreadability,2)Avoidingerrorsinrelatedtechnologies,3)Potentialperformancebenefits,and4)Improvedcollaborationwithinteams.

CSS Case Sensitivity: Understanding What Matters CSS Case Sensitivity: Understanding What Matters Jun 20, 2025 am 12:09 AM

CSSismostlycase-insensitive,butURLsandfontfamilynamesarecase-sensitive.1)Propertiesandvalueslikecolor:red;arenotcase-sensitive.2)URLsmustmatchtheserver'scase,e.g.,/images/Logo.png.3)Fontfamilynameslike'OpenSans'mustbeexact.

What is Autoprefixer and how does it work? What is Autoprefixer and how does it work? Jul 02, 2025 am 01:15 AM

Autoprefixer is a tool that automatically adds vendor prefixes to CSS attributes based on the target browser scope. 1. It solves the problem of manually maintaining prefixes with errors; 2. Work through the PostCSS plug-in form, parse CSS, analyze attributes that need to be prefixed, and generate code according to configuration; 3. The usage steps include installing plug-ins, setting browserslist, and enabling them in the build process; 4. Notes include not manually adding prefixes, keeping configuration updates, prefixes not all attributes, and it is recommended to use them with the preprocessor.

What are CSS counters? What are CSS counters? Jun 19, 2025 am 12:34 AM

CSScounterscanautomaticallynumbersectionsandlists.1)Usecounter-resettoinitialize,counter-incrementtoincrease,andcounter()orcounters()todisplayvalues.2)CombinewithJavaScriptfordynamiccontenttoensureaccurateupdates.

CSS: When Does Case Matter (and When Doesn't)? CSS: When Does Case Matter (and When Doesn't)? Jun 19, 2025 am 12:27 AM

In CSS, selector and attribute names are case-sensitive, while values, named colors, URLs, and custom attributes are case-sensitive. 1. The selector and attribute names are case-insensitive, such as background-color and background-Color are the same. 2. The hexadecimal color in the value is case-sensitive, but the named color is case-sensitive, such as red and Red is invalid. 3. URLs are case sensitive and may cause file loading problems. 4. Custom properties (variables) are case sensitive, and you need to pay attention to the consistency of case when using them.

Case Sensitivity in CSS: Selectors, Properties, and Values Explained Case Sensitivity in CSS: Selectors, Properties, and Values Explained Jun 19, 2025 am 12:38 AM

CSSselectorsandpropertynamesarecase-insensitive,whilevaluescanbecase-sensitivedependingoncontext.1)Selectorslike'div'and'DIV'areequivalent.2)Propertiessuchas'background-color'and'BACKGROUND-COLOR'aretreatedthesame.3)Valueslikecolornamesarecase-insens

See all articles