Try implementing a dynamic id to modify the background when hovering over the menu in the DAWN THEME

I have successfully created an editable section in the customizer where you can upload desktop and mobile images, as well as modify the menu. My current dilemma is how to associate these background images with each "Details-id" and have them change when a user hovers over them. I am utilizing the nav-component and would like to make modifications to global.js using code from the dawn theme.

Feel free to check out the preview of this developmental theme here:

If anyone could provide guidance on this matter, it would be greatly appreciated. Thank you in advance!


This is my current setup; where should I insert the new HTML code?

<script>

    //megamenu hover
    let items = document.querySelector(".aside__nav").querySelectorAll("details");
    items.forEach(item => {
        item.addEventListener("mouseover", () => {
            item.setAttribute("open", true);
            item.querySelector("ul").addEventListener("mouseleave", () => {
                item.removeAttribute("open");
            });
            item.addEventListener("mouseleave", () => {
                item.removeAttribute("open");
            });
        });
    });

    //megamenu image show on hover
    var $activeElement = $(".megamenu-text");
    $(".custom-mega-img").hover(function(){
        $(this).find(".megamenu-img").addClass( "active" );
    }, function(){
        $(".megamenu-img").removeClass( "active" );
    });

</script>
{CSS Code Goes Here}
{Additional Code Block}

Answer №1

Dynamic navigation rarely displays an accurate number of navigation links. It's advised to refer to a collection within the navigation. This way, you'll be able to retrieve the featured image and include an option for a different mobile image by adding an image picker. Insert the following HTML code into the header.liquid file of your DAWN theme.

  //megamenu hover
  let items = document.querySelector(".header__inline-menu").querySelectorAll("details");
  items.forEach(item => {
    item.addEventListener("mouseover", () => {
                          item.setAttribute("open", true);
    item.querySelector("ul").addEventListener("mouseleave", () => {
       item.removeAttribute("open");
    });
    item.addEventListener("mouseleave", () => {
      item.removeAttribute("open");
    });
  });
});

//megamenu image show on hover
var $activeElement = $(".megamenu-text");
$(".custom-mega-img").hover(function(){
        $(this).find(".megamenu-img").addClass( "active" );
   }, function(){
  $(".megamenu-img").removeClass( "active" );
    });
details-disclosure>details {
    position: inherit;
}
.list-menu--disclosure {
    position: absolute;
    left: 0;
    right: 0;
    margin: 0 auto !important;
    width: 90% !important;
  min-width: 90% !important;
  z-index: 2 !important;
      height: 30vh;
}

span.megamenu-img{
  text-align: center;
  width: 65%;
}
.desktop-feature-img{display: none;position: absolute;top: 0;}
span.megamenu-text{width: 35%;}
span.megamenu-img.active .desktop-feature-img {
    display: block;
  z-index: 2;
}

.list-menu__item--active .desktop-feature-img {
    display: block;
}
<a href="{{ childlink.url }}" class="header__menu-item custom-mega-img list-menu__item link link--text focus-inset caption-large{% if childlink.current %} list-menu__item--active{% endif %}"{% if childlink.current %} aria-current="page"{% endif %}>
  <span class="megamenu-text">{{ childlink.title | escape }}</span>
  <span class="megamenu-img">
       {% if childlink.object.featured_image != blank %}
            <img src="{{ childlink.object.featured_image | img_url: 'medium' }}" class="desktop-feature-img"> 
        {% endif %}
  </span>
</a>

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

Having trouble fetching results from AJAX objects using vanilla JavaScript?

I am currently working on developing my own AJAX prototype without relying on jQuery or any other libraries. However, I am facing an issue where I cannot retrieve any results and the breakpoint set on a specific line is not triggering: The problem seems t ...

Fluid Grid design showcasing a gap on the right side

After working on the Skeleton Framework and making adjustments to the grid design, I am facing a small gap issue on the right side. Despite things slowly falling into place, this minor gap is causing confusion. Please refer to the image below for clarifica ...

It's possible for anyone to enhance the appearance of the Download button by adding styles without compromising its functionality

Looking to enhance the style of the Download button as it appears too formal. Seeking assistance in adding some button styles to make it more stylish. The code is correct, just aiming to give the Download button a trendy look with specified styles. ...

Are you harnessing the power of Ant Design's carousel next and previous pane methods with Typescript?

Currently, I have integrated Ant Design into my application as the design framework. One of the components it offers is the Carousel, which provides two methods for switching panes within the carousel. If you are interested in utilizing this feature using ...

Example of a line graph implementation using a d3 array as input

I am a d3 newbie and I am trying to learn by working with the d3.js line example. The code for this example is provided below. My goal is to adjust it to use model data that I already have in a json object format. However, I am struggling with translating ...

Can Reactjs handle passing various properties to a single function using identical buttons?

[Newbie with React]: I'm facing an issue with my code that seems simple. I have two number counters with buttons to add a number to them. I want these buttons to perform the same math function but with the property assigned to them. However, it seems ...

Is there a way for me to invoke a function at the location of this particular code comment?

I have a question that I couldn't find the answer to online. How can I invoke a function at the specified location in the code snippet below? if (drawTile != 0) { roomTilesCoordinates.push( { Coordinate: (i - j) * tileH / 34 + ',&ap ...

Practical strategy for developing and launching a TypeScript/Node.js application

I'm currently developing a node.js app using Typescript, which requires compilation to JS before running. As someone with a background in java/jvm, I'm hesitant about the deployment process where code is pushed to git, built/compiled on the serve ...

Google Book API is a tool provided by Google that

I am trying to loop through the items array provided by the Google Books API and display the result within a div, but I'm having trouble doing so. Here is my current code: <body> <div class="main-body"> <form id="form"> ...

creating a dynamic loop based on an object's key in javascript

Searching for items in a list can be challenging, especially when hardcoded values are used. handleSearch = e => { const q = e.target.value if(q){ const filtered = this.state.data.filter(o => { return Object.values(o).some(val ...

Struggling with your Dropdown Menu onclick functionality in Javascript? Let me lend

I am seeking assistance with implementing a Javascript onclick Dropdown Menu. The current issue I am facing is that when one menu is opened and another menu is clicked, the previous menu remains open. My desired solution is to have the previously open menu ...

Tips for transferring information between two distinct pages utilizing the jQuery POST technique

I'm dealing with two PHP files called card_process.php and payment.php. My goal is to transfer data from the cart_process page to the payment page. Here's a snippet of the code: In cart_process.php: $paynow = "<button type='submit' ...

Data from previous ajax calls is stored and retained when a custom event triggers the call

Good day everyone, I am currently encountering an issue with a tracking mechanism built in jquery. The concept revolves around having a handler attached to multiple clickable elements. When a user clicks on an element, the handler captures a code related t ...

I am facing issues with getting the delete function to properly function in my React

Issue with Delete Button Functionality in React While I am able to successfully delete an item using axios call in Postman, implementing the same functionality on the front-end in a React component seems to be causing problems for me. <button onSubmit ...

Using ReactJS to dynamically change styles based on state variables can sometimes cause CSS

Currently delving into the world of React. Learning about states/props and the art of dynamically altering elements. I've set up the component states like this: constructor(props) { super(props); this.modifyStyle = this.modifyStyle.bind(thi ...

The getelementbyid function is unable to locate the specified button identifier

As I dive into the world of Javascript, I wanted to create a simple input form with a corresponding response field on my website. However, I encountered an issue where using a basic submit button caused the page to refresh and erase the textfields before ...

Responsive screen sizing in Vue.js

https://i.stack.imgur.com/8qwpn.png I added a margin-left to my component due to it being blocked by the side-bar and the "Roles" table. Is there a way to shift my table to the right when the screen width is less than 992? I need it to be responsive acro ...

What is the most effective way to add HTML from a dynamically loaded document using AJAX?

I am attempting to attach the information from a .html file to the body of my main webpage. Essentially, I am striving to create a reusable section of html that can be loaded into any page with a basic JavaScript function. Below is the content of my navig ...

You do not have the authorization to access this content

I have been working on a Laravel web application to upload images into a data table and allow users to download the uploaded image on click. Initially, everything was working fine until I made changes in the code from return '{!! Html::link('ima ...

What is the best way to create a PHP array using JSON?

Is there a way to create a JSON-based array using the json_encode() function in PHP? I am looking for help on achieving the following array format: callback([{"ProductID":1,"ProductName":"Chai","UnitPrice":18,"UnitsInStock":39,"Discontinued":false}]) Als ...