Avoid clicking in areas outside the perimeter of the blue circle in the SVG

Is there a way to restrict clicking outside the blue circle?

The goal is to only allow opening by clicking on the svg itself,

This includes everything, even white space inside the svg.

How can this be achieved in the code?

The current behavior is that clicking on the blue svgs triggers them to open up.

Check out the code snippet here

const manageCover = (function makeManageCover() {
  const config = {};

  function show(el) {
    el.classList.remove("hide");
  }

...
Likesuffixwasahaplessquirreltherezystawakenedquizzicalbarkingallergy nostrilbranchworenviousbyareyardgothroughfuneralspendensignschosecandidlyamimosaenoughneglect summaryreachable sagtotorpor lookupspurnemitshredding requiredovergoingwhatsoeverdiscerndbymaternitytoothpick somberembraceoutskystripequizdenizen blackmailscavengersupplicationtrek21stsnubdecadexplanation requirement scapeexploringfactoranity9:29deceptive overcast else tempestire***/

@keyframes fadebody {
  0% {
    opacity: 0;
  }

  100% {
    opacity: 1;
  }
}

.outer {
  display: flex;
  flex-wrap: wrap;
  min-height: 100%;
  width: 310px;
  box-sizing: border-box;
  justify-content: center;
  align-content: center;
  margin: auto;
  gap: 20px;
  padding: 0;
}


.outer.isOpen {
  display: ...

</ul>

Answer №1

To properly define which elements of the SVG should respond to pointer events, you can use the following approach:

<svg class="playa thePlay" width="64" height="64" viewBox="0 0 64 64" pointer-events="none">
  <g id="play">
    <title>Play</title>
    <circle cx="32" cy="32" r="32" fill="transparent" pointer-events="visiblePainted" />
    <path d="M25.6,46.4L44.8,32L25.6,17.6V46.4z M32,0C14.3,0,0,14.3,0,32s14.3,32,32,32s32-14.3,32-32S49.7,0,32,0z
    M32,57.6C17.9,57.6,6.4,46.1,6.4,32S17.9,6.4,32,6.4S57.6,17.9,57.6,32S46.1,57.6,32,57.6z" />
  </g>
</svg>

You can ensure that the pointer-events="none" property is applied to all SVG elements using CSS.

svg.thePlay {
 pointer-events: none;
}

Please see the complete code snippet for managing video players and cover elements below:

[Complete code snippet provided]

Answer №2

To achieve the desired effect in the SVG, consider adding a transparent circle or path that matches the icon either above or below the existing path. Ensure to set its fill to transparent.

<circle fill=transparent cx="32" cy="32" r="32"/>

Additionally, assign a unique class to the group inside the SVG. For example, you can use class="justTheIcon" for the group and reference it in the manageCover.init function.

  manageCover.init({
    container: ".container",
    playButton: ".justTheIcon"
  });

Check out this updated version of your JSFiddle with the embedded code:

const manageCover = (function createManageCover() {
  // Implementation details here...
}());

const videoPlayer = (function generateVideoPlayer() {
  // Video player logic here...
}());


const managePlayer = (function makePlayerManager() {
  // Player management functionality here...
}());


function onYouTubeIframeAPIReady() {
  // Initialization code here...
}
html,
body {
  /* CSS styling rules */
}

/* Additional CSS styles */

.outer {
  /* More CSS properties */
}

.container {
  /* Container styles */
  display: flex;
  justify-content: center;
}

/* Animation keyframes */

@keyframes fade {
  /* Fade animation details */
}

/* Other CSS classes and animations */

.hide {
  /* Hide elements */
}
<ul class="outer">
    <li class="container">
      <svg class="playa thePlay" width="64" height="64" viewBox="0 0 64 64">
        <g id="play" class="justTheIcon">
          <title>Play</title>
          <circle fill=transparent cx="32" cy="32" r="32"/>
          <path d="M25.6,46.4L44.8,32L25.6,17.6V46.4z M32,0C14.3,0,0,14.3,0,32s14.3,32,32,32s32-14.3,32-32S49.7,0,32,0z
          M32,57.6C17.9,57.6,6.4,46.1,6.4,32S17.9,6.4,32,6.4S57.6,17.9,57.6,32S46.1,57.6,32,57.6z" />
        </g>
      </svg>
      <div class="inner-container curtain curtain1">
        <!-- Inner container content -->
      </div>
    </li>
    <!-- Add more li elements as needed -->
  </ul>

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

Replace the image source with a list of images

I am looking to create a dynamic image list using either an array or an HTML list. When I hover over an image, it should change one by one with a fade or slide effect, and revert back to the default images when I hover out. Question 1: What type of list s ...

What is the best way to retrieve a response from a PHP file as an array through Ajax?

Seeking assistance in retrieving a complete address by entering the postal code in an HTML form textbox and clicking a button. The setup involves two files - one containing the ajax function and the other housing the PHP code. Uncertainty looms over whethe ...

Passing a reference to a react functional component (react.FC) results in a type error: The property ref is not recognized on the type 'IntrinsicAttributes & Props & { children: ReactNode}'

Currently, I am working on mastering the utilization of forward refs. In a functional component (FC), I am trying to initialize all my refs and then pass them down to its child components so that I can access the canvas instances of some chartjs charts. Ho ...

Place a Three.js scene within a jQuery modal dialogue box

I am attempting to integrate a Three.js scene into a jQuery modal window. The objective is to utilize the Three.js scene in a larger window size. This scene should be displayed after clicking on an image that represents the scene in a smaller dimension. Y ...

Obtain text content using JQuery and AJAX rather than retrieving the value

I am struggling with a dynamic table that needs to perform calculations before submitting, requiring the presence of values. However, I want to submit the text from the options instead of the values. Despite trying various approaches, none of them seem to ...

Conceal excessive content on elements set in a stationary position

How can we prevent overflow of a fixed div within a container? Initially, I attempted nesting fixed elements inside each other, but that did not solve the issue. The only solution that comes to mind is using "inverted" masks: other fixed divs that hide eve ...

Is there a way for me to streamline the process of logging in using either Google or Facebook?

Is there a way for me to automate the scenario if I'm unable to locate the element using Appium Uiautomator? https://i.stack.imgur.com/Rjji4.png ...

Customize MUI Tabs to resemble the design of Bootstrap Nav Tabs

Looking to customize Material UI Tabs to resemble Bootstrap Tabs. Made significant changes, but struggling with removing the border-bottom on the activeTab. In Bootstrap, they use marginBottom: -1px on the active tab, but it doesn't work for me. Any s ...

After applying the rotateY function, the z-index appears to be malfunctioning

My current project involves creating a page flip effect, which requires two overlapping div elements. Initially, both divs are side by side with the second div having a -webkit-translateY(180deg) property applied to it. The first div has a z-index of 2, wh ...

Invoking Ajax Within Every Loop

I am creating dynamic HTML buttons where, upon pressing each button, I want to make an AJAX call to retrieve a value. However, I am encountering an issue where I get as many console outputs as the number of buttons pressed. Here is my PHP code: if(isset($ ...

Change not accepted

I am a beginner in Angular and still grappling with the fundamentals. On my menu, I have a cart icon with an initial value of 0 upon first load. In my product list, each product has an 'AddToCart' button. What I aim to achieve is- I want to dy ...

There was a failure to retrieve any data when trying to send an ajax request to

When attempting to send JSON data to my PHP, I am not receiving any response when accessing it in my PHP code. Below is the Ajax request being made: var project = {project:"A"}; var dataPost = JSON.stringify(project); $.ajax({ url: 'fetchDate.p ...

Update the image source within a CSS element

I'm facing an issue with changing the source image of an Element. The situation is that I have a customized CSS script and I need to modify a logo image. Below, you can find the source code: https://i.stack.imgur.com/8HLCE.png The problem lies in at ...

Achieving horizontal alignment for divs in CSS can be challenging

Struggling to align three circular divs on my webpage, here's the code: <div class="row"> <div class="large-9 push-2 columns"> <div class="green"></div> <a href="#">Donnez</a> </div> <div cl ...

How can you combine accessibility with absolute positioning?

Have you seen our unique hamburger design? https://i.stack.imgur.com/AmT6P.png A simple click will reveal a neat popup (the class "open" is added to a div). https://i.stack.imgur.com/yPydJ.png This cool effect is achieved using fixed positioning, but i ...

The Gulpfile.js encountered an error while trying to load

My Visual Studio task runner is having trouble loading the gulp file. I am currently using VS2017 v15.9.4, but the project was developed some years ago. Failed to run "...\Gulpfile.js"... cmd.exe /c gulp --tasks-simple assert.js:350 throw err; ...

Discovering a way to retrieve objects from an array of objects with matching IDs

Here is a code snippet I put together to illustrate my objective. arr = [ { id:1 , name:'a', title: 'qmummbw' }, { id:2 , name:'b', title: 'sdmus' }, { id:2 , name:'', title: 'dvfv' }, ...

The message of error is undetermined

Can someone help me with using the errorMessage object from routes in a partial? I have attempted to implement it as shown below: Route:- const express = require("express"); const router = express.Router(); const Character = require("../models/character" ...

What is the best way to export image paths using require() from a single index.js file in a React Native project?

I am looking for a way to efficiently export all images from a single file named index.js, so that in the future, if I need to change the path of an image, I only have to make changes in one file. For example: export {default as avatar} from './avata ...

What is the best way to toggle DOM classes in React using Material-UI components?

Currently utilizing Material UI alongside React, I have a div element: <div className={classes.div}></div> I am attempting to dynamically add a conditional class to it: <div className={classes.div + divActive ? `${classes.div}__active` : &a ...