Detecting a click on the background div in Angular without capturing clicks on child divs

Over at ollynural.github.io, I've been working on creating a pop-up div in the portfolio page that provides additional information about the project you select. To close the pop-up, I have implemented an ng-click feature so that clicking on the main portfolio-pop-up container will remove it.

I'm wondering if it's possible to only remove the parts of the portfolio-pop-up div that are visible (not including the photo or the description white box) when clicked? This way, users can freely click on the image and the white box without closing the entire div.

<div class="portfolio-pop-up container" ng-click="losePortfolioFocus()">
            <div class="row">
                <div class="col-xs-12">
                    <img class="portfolio-image portfolio-image-popup" src="{{portfolioImageClass}}">
                </div>
                <div class="col-xs-12 pop-up-container">
                    <div class="pop-up-row">
                        <div class="col-xs-9" style="background: red">
                            <h1>
                                {{portfolioTitle}}
                            </h1>
                            <p>
                                {{portfolioDescription}}
                            </p>
                        </div>
                        <div class="col-xs-3" style="background: cyan">
                             <a href="{{portfolioLink}}">Click me</a>
                             <div ng-repeat="tech in portfolioTech">
                                {{tech}}
                             </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

Javascript

$scope.losePortfolioFocus= function() {
    angular.element('.portfolio-pop-up').css("display", "none");
}

CSS

.portfolio-pop-up {
    display: none;
    position: absolute;
    width: 100%;
    height: 100%;
    /* color with alpha transparency */
    background-color: rgba(0, 0, 0, 0.70);
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
}

If anyone has any suggestions or needs more CSS/code examples for assistance, please feel free to let me know. Your help is greatly appreciated!

Answer №1

If you want to prevent the click event from bubbling up in the element containing the pop-up's content, you can use the following code:

<div class="popup-container" on-click="stopClickPropagation()">
  <div class="inner-content" on-click="$event.stopPropagate()">
  ...
  </div> 
</div>

By doing this, the click event will not trigger the function stopClickPropagation() when clicking inside the pop-up.

Answer №2

My recommendation is to trace back up the event chain starting from the target event and verify if your pop-up-container is included in it. This approach will allow you to differentiate between a click inside the pop-up and a click outside of it.

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

Show all outcomes when a checkbox is not checked using AngularJS filters

I find myself stuck on a seemingly simple task that's causing me some frustration. Within an AngularJS app, I have a dictionary of values that I need to filter using a checkbox. When the checkbox is checked, I want to display only the elements with & ...

Ways to merge two sets in Mongoose and arrange them based on their createdDate

Currently, I am working on a MEAN.js application that involves two specific documents: var RingtoneSchema = new Schema({ language: { label: String, code : String }, deliver:{ type:Boolean, ...

HTML - Image is only partially visible

While attempting to set up this theme for my blog, I encountered a minor issue - the avatars in the comment section are not displaying correctly, as they appear to be cut off along with the container. Despite numerous attempts to edit the code, I have be ...

Is it possible to delay the execution of the code until the ajax function has completed

After executing the fillContent function, I need to call beginEditingQuestion. fillContent(cid, "questions"); beginEditingQuestion(qid); The issue is that beginEditingQuestion can't be executed until all the ajax requests in fillContent are complete ...

What is the best way to insert a button at the end of the last row in the first column and also at the

I am working on a JavaScript project that involves creating a table. My goal is to dynamically add buttons after the last row of the first column and also at the top of the last column. for (var i = 0; i < responseData.length; i++) { fo ...

There seems to be an issue with $(window).scrollTop() not functioning properly in Safari

While it works smoothly on Firefox and Chrome, there seems to be an issue with Safari. Here is the code snippet: function founders() { var scrollPos = $(window).scrollTop(); if (scrollPos == 900) { $(function() { $(".first_fall").f ...

Error 400: Token Obtain Pair request failed in Django REST with simpleJWT and Vue 3 composition API

I'm encountering an issue with obtaining the refresh and access tokens when sending a form from my Vue app to the Django REST API. CORS has been enabled, and signing up through the REST API page or using Postman doesn't pose any problems. However ...

How to Use CSS to Copy a Style Path and Conceal an Element within an iFrame

My goal is to adjust a division by including a width element in its CSS properties. I have attempted to use Chrome and Firebug to copy the CSS path, but it seems that the result is incorrect. After inserting it into my style.css file, the division remains ...

Achieving enlightenment with Satori in NextJS: Transforming SVG to PNG in a NodeJS Environment

I am currently exploring the capabilities of satori and integrating it into my next.js api routes. (I'm unable to utilize the vercel/og package). While I have successfully set everything up, I'm facing a challenge in converting the svg image gen ...

What steps can I take to mimic a pen-like behavior for my cursor on my sketching website project?

My goal is to create a 16x16 grid with a white background, where each grid item changes color when the mouse is pressed and moved over it, similar to paint. I have written a script to achieve this: let gridContainer = document.getElementById('grid-con ...

Prevent vertical scrolling on touch devices when using the Owl Carousel plugin

Is there a way to prevent vertical scrolling on Owl Carousel when dragging it horizontally on touch devices? It currently allows for up and down movement, causing the whole page to jiggle. If anyone has a solution, I can share the JavaScript file. Appreci ...

Utilizing a TypeScript definition file (.d.ts) for typings in JavaScript code does not provide alerts for errors regarding primitive types

In my JavaScript component, I have a simple exporting statement: ./component/index.js : export const t = 'string value'; This component also has a TypeScript definition file: ./component/index.d.ts : export const t: number; A very basic Typ ...

Apply CSS styling to the entire element when hovering over its pseudo-element 'after'

I am working on a button/speech bubble design with a unique hover effect. Here is the current setup: https://i.stack.imgur.com/4OrpL.png Here is the code snippet for the button: <div value="GO" id="go-div" class="bubble"> <input type="submit ...

Transferring information from a function-based module to a higher-level class component in React Native

I'm currently working on an application that has a tab navigation. One of the screens in the tab is called "ScanScreen," where I'm trying to scan a UPC number and send it to the "HomeScreen" tab, where there's a search bar. The goal is for t ...

Guide to incorporating a Menu feature into your MVC 5 application

After creating an MVC 5 project, the decision was made to change the menu by incorporating Bootswatch. The desired menu to implement is displayed below: https://i.sstatic.net/2vqxn.png The initial step involved modifying the general style of the project ...

Is there a way to monitor the home button press event within a PhoneGap application?

Hello! I'm curious if there is a way to track when the Home button is pressed on both Android and IOS using phonegap phonegap build. I have looked into events for the home button press, but have only found information on back button events so far. ...

I have a json file that I need to convert to a csv format

I am currently working with a json file, but I need to switch it out for a csv file. Do I have to use a specific library to accomplish this task, or can I simply modify the jQuery 'get' request from json to csv? I attempted the latter approach, b ...

What is the best way to enable a DOM element's height to be resized?

I have a widget displayed in the corner of my browser that I would like to make resizable by dragging the header upwards to increase its height. The widget's position remains fixed with its bottom, left, and right properties unchanged, but I need the ...

Using Javascript to organize data in a table

I have a basic HTML table setup that looks like this: <table id="myTable"> <thead> <tr> <th class="pointer" onClick="sortTable()">Number</th> <th>Example3</th> <th ...

magnificPopup experiencing difficulties when attempting to invoke a class that is dynamically generated within the HTML document

Currently, I am encountering an issue with the magnificPopup. Whenever I try to trigger the popup using the class 'popup-with-zoom-anim', it doesn't seem to work as expected. Has anyone else faced a similar problem before? <body> < ...