目前,当用户将鼠标悬停在链接或文本上时,我正在页面顶部显示一个弹出窗口。但是,问题是弹出窗口在屏幕上无法正确显示。弹出窗口的顶部在浏览器中不可见。我的应用程序中使用了Twitter Bootstrap。如何使弹出窗口显示在元素的右侧而不是顶部?
任何帮助都非常感激,谢谢。
function showPopup(element) {
elements = $(".popuptext")
$.each(elements, function(i, e) {
e.classList.remove("show");
})
popup_id = $(element).attr("data-popup-id")
var popup = document.getElementById(popup_id);
popup.classList.add("show");
}
function hidePopup(element) {
popup_id = $(element).attr("data-popup-id")
var popup = document.getElementById(popup_id);
popup.classList.remove("show");
popup.classList.add("hide");
}
/* Popup container - can be anything you want */
.popup {
position: relative;
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: 350px;
background: #ffffff;
color: #585858;
text-align: center;
border-radius: 6px;
border: solid 1px black;
padding: 8px 0;
position: absolute;
z-index: 1;
bottom: 125%;
/*left: 100px;*/
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;
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="popup">
<a href="/my-link" data-popup-id="popup-c5e1e2c5" onmouseenter="showPopup(this)">Hover On this text</a>
<span class="popuptext show" data-popup-id="popup-c5e1e2c5" id="popup-c5e1e2c5" onmouseleave="hidePopup(this)">
My Whole content
</span>
</div>