Display the div upon hovering and ensure that it is click-through

I've been working on a music player project. You can check out the live version here:

For the music player base, I am utilizing this audio visualizer: https://github.com/DavidLazic/audio-visualizer. My goal is to customize it according to my needs by adding a play icon that appears when the user hovers over the album image (the music player).

However, I encountered an issue where the click event of the music player is linked to the canvas element beneath the play icon. Here's the code snippet:

<div class="playcircle">
    <i class="playbtn fa fa-play fa-4x"></i>
    <img class="albumcover" src="summer.jpg" alt="Card image cap ">
</div>

<div class="vz-wrapper">
    <audio src="summer.mp3" controls id="myAudio"></audio>
    <div class="vz-wrapper -canvas">
        <canvas id="myCanvas" width="550px" height="420px"></canvas>
    </div>
</div>

I tried utilizing a :hover function for the canvas like this:

.playbtn {
    opacity: 0;
    position: absolute;
    top: 0.9em;
    left: 1.1em;
}

#myCanvas:hover .playbtn {
    opacity: 1;
}

Unfortunately, this approach did not work as the play button did not appear at all. Connecting it to any other div also did not solve the issue.

The crucial aspect is that the user should be able to start the music by clicking anywhere on the album cover. The music player has its own function for handling click events, and making changes to the existing code could potentially break the player entirely. Here's the function:

Visualizer.prototype.bindEvents = function () {
    var _this = this;

    document.addEventListener('click', function (e) {
        if (e.target === _this.canvas) {
            e.stopPropagation();
            if (!_this.isPlaying) {
                return (_this.ctx.state === 'suspended') ? _this.playSound() 
: _this.loadSound();
            } else {
                return _this.pauseSound();
            }
        }
    });

    if (_this.autoplay) {
        _this.loadSound();
    }

    return this;
};

I managed to get it to work partially by linking the :hover effect to .playcircle, but then the icon was not clickable to start the music. I attempted to address this by using pointer-events: none;, but it disabled both hovering and clicking on the album cover.

I also experimented with jQuery without success. I tried solutions like this one: Click through div, which seemed promising but didn't yield the desired outcome.

Thank you in advance for any assistance!

Answer №1

Update the .playcircle CSS class by adding a "z-index" property with a value of 100.

.playcircle {
    ...
    z-index: 100;
}

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 necessity for including "overflow" in the code?

http://www.example.com/css/tryit.asp?filename=trycss_dropdown_navbar The link provided above showcases the practice background of a certain website. In the code on the left side, specifically under the style section, there is a "ul" element where the "ove ...

How can I showcase an image from the search results using the Giphy API?

Find the GitHub link to the Giphy API here: https://github.com/Giphy/GiphyAPI. As a newcomer, I'm facing a roadblock. Currently, I am receiving random gifs from the Giphy API instead of the specific search result requested by the user. Is there a wa ...

Are HTML attribute names really case-sensitive? A topic filled with conflicting information

After learning that attribute names are case-sensitive, I found conflicting information. A source mentioned that attribute names are indeed case-sensitive. For example, the width attributes in <div> and <DIV> would be considered separate due ...

How can one determine the most accurate box-shadow values?

I am trying to extract the precise box-shadow parameters from a CSS style rule generated by the server. My main focus is determining whether the element actually displays a visible shadow or not. There are instances where the shadow rule is set as somethi ...

Listening attentively for sliding events in Vuetify Vue, capturing the value only when necessary

After installing the vuetify plugin for my project to utilize a colorpicker plugin, I encountered specific requirements that necessitated manual adjustments to the function and style of the plugin. https://i.sstatic.net/8bM8L.png The current plugin inclu ...

Ways to securely conceal an API key within an AJAX request

Is there a way to perform an AJAX request directly on the desktop without revealing the secret API key to the client? The issue is that my AJAX request requires a "secret API Key" which I do not want the client to have access to. This is my current JavaS ...

Shift the <tfoot> table to the right using CSS

Is there a way to shift the red area (x1, x2) to the right using only CSS in a table where the <tfoot> tag cannot be edited? https://jsfiddle.net/qL03728p/ table { width: 100%; border-collapse: separate; } table td { border-top: 1px solid ...

The canvas div wrapper flexbox item is in need of scrollbars

I am looking to display a canvas that may be larger than the viewport size. The layout structure will include navigation on the left and controls on the right, with the canvas positioned in between them. When the canvas is too large for the screen, I wan ...

Output a specific portion of the webpage

After extensive research, I have been trying to find a solution that will enable me to print only a specific section of a webpage. Many sources suggest the following steps: Include in HTML head: <link rel="stylesheet" type="text/css" media="print" hr ...

Recognize different HTML components when an event occurs

My application is equipped with a multitude of buttons, inputs, and other elements that trigger different events. I am looking for a way to easily differentiate between each element and the event it triggers. For instance, consider the following snippet f ...

Resize a division to fill the window while maintaining original proportions

Is there a way to resize a div so that it fills the entire browser viewport while maintaining its aspect ratio? How can I achieve this using CSS, JQuery, or both? ...

When using jQuery and CSS to dynamically change properties, the element may receive scroll

<!DOCTYPE html> <html> <head> <title>CUSTOM PAGE</title> <meta charset="utf-8"> <meta content="width=device-width, initial-scale=1" name="viewport" /> <link rel="stylesheet" href="https://use ...

Significant lag experienced in my jQuery function execution caused by the abundance of values present in my select form elements

I created a .php page that contains around two hundred select form elements. These elements are populated with values from a .txt file located in the same directory using PHP: <?php $schoolselected = 'schools.txt'; $eachlines1 = file($schools ...

How can I retrieve the source code of a popup window and save it as

Is there a method to save the content of a popup window from an external domain as a string, when opened with: window.open('html'); Alternatively, is it possible to redirect the output of the popup into a string? For example, using Chrome' ...

Tips on aligning a span inside a div to the right and ensuring the text is responsive

I want to enhance my bar designing skills. I managed to create one, but I'm facing some issues. How can I make this span align to the right? I tried using float but it didn't work. Any suggestions? Also, when I try to shrink the screen, the text ...

What is the best way to retrieve an image using AJAX and jQuery?

Is it possible to display an image using ajax jquery in a different way? $.ajax({ url: "c.jpeg", type :"get", dataType: "image/jpeg", success: function(data) { $("#myimg2").attr("src",data); } }) Here is the correspo ...

Modify the CSS class of a <TD> element depending on the value of the column using JavaScript

I am working on a grid where I need to dynamically change the CSS of one of the columns based on the value from another field in the result set. Instead of simply assigning a class like <td class='class1'> ${firstname} </td> I ...

Retrieve the value from an input tag that is only displayed based on a condition using *ngIf

In my HTML form, I have implemented conditional visibility of input fields based on the radio button selection using *ngIf. <table> <tr> <td><label>name</label></td> <td><input #name />&l ...

Guide on preventing the selection of a dropdown value that has already been chosen in a previous row within a jQuery populated HTML table

Hey there! I've been working on some HTML using jQuery (3.x) and Bootstrap (4.x). You can find the code here. My main question is, how can I exclude the dropdown value that was selected in the previous row? Let's say, for example, if I chose "Le ...

ASP.net is encountering difficulty locating a specific JavaScript function

Seeking assistance to comprehend the issue, I have devoted countless hours scouring Google for a resolution. Current tools in use: ASP.NET entity framework Within a view, the following code is utilized: <button type="button" id="btnGraf ...