Slice an interactive div

I am currently working on setting up a horizontal sliding div for a menu. The layout consists of a left DIV that remains visible at all times, and a sliding DIV that appears horizontally when the menu is activated. My HTML code looks like this.

<div id="app-menu">
  <div id="menu_left">
    <img src="menu_left.png" />
  </div>
  <div id="menu_slider" class="menu-content">
    <img src="menu_1.png" />
    <img src="menu_2.png" />
    <img src="menu_3.png" />
  </div>
</div>

The animation of the slider is achieved using CSS as shown below:

.menu-content {
    position: fixed;
    height: 175px;
    left: -606px;
    top: 35px;
    overflow-x: hidden;
    overflow-y: hidden;
    transition: ease-in-out 400ms left;
}

.menu-content-opened {
    left: 125px;
    transition: ease-in-out 600ms left;
}

The class of the menu_slider DIV toggles between 'menu-content' and 'menu-content-opened' in a click event on the menu_left DIV, which functions correctly.

However, my menu_left DIV includes an image called menu_left.png with an alpha channel and transparent areas. When the menu_slider DIV closes behind the menu_left DIV by sliding to the left, I can see the content of the menu_slider DIV peeking through those transparent areas.

My goal is to have the menu_slider DIV slide to the left without being visible behind the menu_left DIV, essentially cropping it somehow. While one solution could be to fill in the transparent areas of the PNG with the page background color, I would prefer not to do so. I am currently utilizing Angular 6, Typescript, and .less style files for this project.

If you have any suggestions or ideas, please feel free to share them. Thank you!

Answer №1

One way to add animation is by animating the property max-width instead of using left. This can prevent layers with transparency from mixing together, providing a cleaner effect.

Check out this practical example:

const menuDiv = document.getElementById('menu_left');
  menuDiv.addEventListener('click', () => {
    let slider = document.getElementById('menu_slider');
      slider.classList.add('menu-content-opened');
      console.log('clicked');
    });
    .menu-content {
        position: fixed;
        height: 175px;
        left: 120px;
        max-width: 0;
        /* left: -606px; */
        top: 35px;
        overflow-x: hidden;
        overflow-y: hidden;
        transition: all ease-in-out 400ms;
    }

    .menu-content-opened {
        max-width: 600px;
    }
    #menu_left {
      background: gray;
      width: 100px;
    }
<div id="app-menu">
  <div id="menu_left">
    <img src="https://pngimage.net/wp-content/uploads/2018/06/png-transparent-background-2.png" alt="MENU LEFT"/>
  </div>
  <div id="menu_slider" class="menu-content">
    <img src="menu_1.png" alt="menu 1" />
    <img src="menu_2.png" alt="menu 2"/>
    <img src="menu_3.png" alt="menu 3"/>
  </div>
</div>

Answer №2

To switch up the appearance of the div element with the identifier #menu_slider when clicked, you can modify the display property. Simply alternate between setting it to {display: none;} and {display: block;}.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best way to align the Storefront Menu in the center?

If you want to reproduce the issue I'm facing, visit the demo page of the storefront here: then remove the node <ul id="site-header-cart" class="site-header-cart menu"></ul> that contains the cart box (located next to the menu) so that on ...

Having trouble with Tailwind CSS not functioning correctly once the font is imported?

I am currently working on a next.js project and utilizing tailwind for styling. I have noticed an odd behavior when importing a custom font into my globals.css file. page.jsx "use client"; import React from "react"; const page = () = ...

Design the spans to have equal heights that adjust dynamically based on the content entered

I'm facing a challenge that I've been trying to resolve using just CSS, but I've hit a roadblock. The issue at hand involves aligning multiple spans next to each other and making them equal in height. The height is not fixed and depends on ...

The correct rendering of background image paths is not functioning properly

Currently, I am utilizing Django Compress to streamline the process of using fewer files in their original format, rather than converting them to CSS files. This method has been successful except for a minor issue with translating the paths for background ...

Mysterious Error Retrieving /v2/me Endpoint from LinkedIn in Angular 11

My goal is to retrieve the r_liteprofile from LinkedIn using the Oauth2 3-legged flow. While it works perfectly in Postman, I keep encountering an 'Unknown Error' in Angular 11: Here's a snippet of the code: params = new HttpParams() .set(& ...

How can I choose specific options by clicking based on the select name's value with web scraping?

I'm attempting to scrape the select dropdown menu below in order to retrieve its text content. Unfortunately, I can't rely on the name attribute as "P889O1" varies for each product from which I need to extract data. I considered using 'cont ...

Showing data from the POST request in a dialog box

Greetings to all! I am in the process of building a webpage to test my API. The goal is to send a form to my nodejs backend and receive a JSON response back. So far, sending the request is functioning properly and I can track its progress on my VPS conso ...

Why is it that when I click outside of the <html> element, the click event bound to the <html> element is triggered?

const html = document.querySelector('html') const body = document.querySelector('body') body.onclick = () => { console.log('body clicked') } html.onclick = () => { console.log('html clicked') } document. ...

Expanding the navigation bar causes it to reach the second row after being translated

I am currently working on a website that will be dynamically displayed in both English and Spanish. One issue I have encountered is that the longer words in Spanish are causing the navigation bar to spill onto a second row. For more details, please visit: ...

Showing information from page's table using find_element_by_xpath (Selenium with Python)

I am currently exploring the implementation of the find_element_by_xpath() method to locate table elements on a webpage and present them in either a display or print format. Below is an excerpt from the page content: <tbody id="listContainer_databody" ...

Creating a dynamic Bootstrap navigation bar using PHP

I created a website using bootstrap, but now I want to add more dynamic features. The tutorial I'm following for this does not involve the use of bootstrap. Am I missing something obvious here? Could you please review my code? (To avoid overloading t ...

[Vue warning]: The property "text" was accessed during rendering, however it is not defined on the current instance using Pug

Looking for some guidance from the Vue experts out there. I've recently started working with Vue and I'm attempting to create a view that verifies an email with a unique code after a user signs up. Right now, my view is set up but it's not c ...

Using jQuery, how can I dynamically change the stacking order of an element when clicked?

I'm struggling to change the z-Index on button click. I have a static image and a dynamic div, and I want to send the #imgDiv1 behind the static image. Unfortunately, despite trying everything, I haven't been able to achieve this. You can check ...

Establish a route nickname for files outside the project directory

I'm currently tackling a project that is divided into multiple angular projects. Within these projects, there are some services that are shared. Is there a way for me to incorporate these services into my project without encountering errors? /root / ...

The custom validation in nestjs is throwing an error due to an undefined entity manager

I've been working on developing a custom validation for ensuring unique values in all tables, but I encountered this error: ERROR [ExceptionsHandler] Cannot read properties of undefined (reading 'getRepository') TypeError: Cannot read proper ...

Using ngFor to destructure two variables simultaneously

When working with Python, I found a way to unpack both variables in each tuple at every iteration. l = [(1, 2), (4, 5), (8, 9)] for k,v in l: print("k = ", k) print("v = ", v) print("-------") # k = 1 # v ...

Working with extensive amounts of HTML in JavaScript

Is there a way to dynamically load large amounts of HTML content in JavaScript? I'm struggling to figure out how to insert all the HTML content into the designated space within the JavaScript code. If anyone knows a different approach or solution, ple ...

The appearance of the pop-up mask is displayed at lightning speed

Check out the demo here Here is the HTML code: <div class="x"> </div> <input class="clickMe" type="button" value="ClickMe"></input> This is the JS code: $(".clickMe").click( function() { ...

Discovering the type in Typescript by specifying a function parameter to an Interface

Consider this sample interface: interface MyInterface { x: AnotherThing; y: AnotherThingElse; } Suppose we make the following call: const obj: MyInterface = { x: {...}, y: {...}, } const fetchValue = (property: keyof MyInterface) => { ...

Creating a menu with items and listeners from a kmllayer - a step-by-step guide

Currently, I am working with a map that includes a kmllayer. This layer has been added using the following code: ctaLayer = new google.maps.KmlLayer('http://www.npd.no/engelsk/cwi/pbl/en/aFactGlobe/disc/ActivityStatus_Producing_labels.kml'); ...