Issue
I'm trying to show some elements in a list of cards and when I click on a card, I need to show a pop-up message on that exact card. Right now it's showing up the top card. But I need to it to show up on the card I click.
Here's my html code for showing card elements and pop-up:
<a class="external" ng-repeat="card in cardData" ng-click="popUpFunction()">
<div class="card">
<img class="card-image" src="{{card.thumbNail_image}}" alt="">
<div class="popup">
<span class="popuptext" id="myPopup">A Simple Popup!</span>
</div>
<div class="card-infos">
<h2 class="card-title">{{card.contentDescription}}</h2>
</div>
</div>
</a>
Here's the css code:
.popup {
position: relative;
display: inline-block;
cursor: pointer;
height:0px;
width:0px;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
/* The actual popup */
.popup .popuptext {
visibility: hidden;
width: 160px;
background-color: #555;
color: #fff;
text-align: center;
border-radius: 6px;
padding: 8px 0;
position: absolute;
z-index: 1;
margin-left: 80px;
}
/* Popup arrow */
.popup .popuptext::after {
content: "";
position: absolute;
top: 100%;
left: 50%;
margin-left: -5px;
border-width: 5px;
border-style: solid;
border-color: #555 transparent transparent transparent;
}
/* Toggle this class - hide and show the popup */
.popup .show {
visibility: visible;
-webkit-animation: fadeIn 1s;
animation: fadeIn 1s;
}
/* Add animation (fade in the popup) */
@-webkit-keyframes fadeIn {
from {opacity: 0;}
to {opacity: 1;}
}
@keyframes fadeIn {
from {opacity: 0;}
to {opacity:1 ;}
}
And here's the js code:
$scope.popUpFunction = function () {
var popup = document.getElementById("myPopup");
popup.classList.toggle("show");
}
Solution
To solve the issue, I passed the index of the card as a parameter and checked it in ng-if
<a class="external" ng-repeat="card in cardData" ng-click="popUpFunction()">
<div class="card">
<img class="card-image" src="{{card.thumbNail_image}}" alt="">
<div class="popup">
<span class="popuptext" id="myPopup" ng-if="popUpIndex==$index">A Simple Popup!</span>
</div>
<div class="card-infos">
<h2 class="card-title">{{card.contentDescription}}</h2>
</div>
</div>
</a>
And here's the change in script file:
$scope.popUpIndex = 0;
$scope.modalFunction = function (ind) {
console.log(ind);
$scope.popUpIndex = ind;
var popup = document.getElementById("myPopup");
popup.classList.toggle("show");
}
Answered By - Araf
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.