lakers1234 lakers1234 - 4 days ago 5
CSS Question

Popup using JavaScript and css

I have created a popup when I click on hello (plane geometry) as shown in the figure, but the popup
appears on the extreme left of the screen I don't know how to make it appear on the plane geometry box
can someone please help me how to fix this. I have also uploaded the code.

enter image description here

function onDocumentMouseDown(event) {
event.preventDefault();
mouse.x = (event.clientX / window.innerWidth) * 2 - 1;
mouse.y = -(event.clientY / window.innerHeight) * 2 + 1;
raycaster.setFromCamera(mouse, camera);
var intersects = raycaster.intersectObjects(pickables);
if (intersects.length > 0) {
if (intersects[0].object.name === "plane")
window.open(intersects[0].object.userData.URL);

// alert ("plane");
else if (intersects[0].object.name === "plane1") {
var popup = document.getElementById('myPopup');
popup.classList.toggle('show');
}
}
}


.popup {
position: absolute;
display: inline-block;
cursor: pointer;
-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;
bottom: 125%;
left: 50%;
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;
}
}



Answer

if i understood your code correct, you are using position absolute on the popup but not giving it any coordinates, so it is on top left of the screen

.popup {
  position: absolute;
  top: 50%; //place it where you want
  left:50%; // place it where you want
  display: inline-block;
  cursor: pointer;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}
Comments