悬停在 content/body 上时保持弹出式悬停内容打开
Keep pop up hover content open while hovering over content/body
我正在尝试使用 javascript 和 css 创建自定义悬停。
一切正常,我可以切换 class 以显示和隐藏 popup/hover 气泡。
(弹出正文)
但是,我希望当光标悬停在气泡上时气泡也保持打开状态。
(弹出正文)
这会在离开弹出窗口后立即关闭-link,如果我在弹出窗口主体内呈现任何 link,悬停操作将变得无用。请帮忙!
HTML/ERB
<div class="popup-container">
<span class="popup-link">Partner disclosure</span>
<span class="popup-body popup-bottom">
<h3>Partner relationships</h3>
<p>stuffs in popup body</p>
</span>
</div>
Javascript
$(document).on('mouseleave click', '.popup-body', function() {
$(".popup-body").removeClass('show-popup');
})
### if mobile device
if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
$(document).on('click', '.popup-link', function() {
var popupContent = $(this).parent('.popup-container').find('.popup-body');
if (!popupContent.hasClass('show-popup')) {
popupContent.addClass('show-popup');
} else {
popupContent.removeClass('show-popup');
}
})
$(document).on('touchstart', '.page-content', function(e) {
if ( !e.target.classList.contains(".popup-body") ) {
$(".popup-body").removeClass('show-popup');
}
});
} else { ###desktop
$(document).on('mouseenter', '.popup-link', function() {
var popupContent = $(this).parent('.popup-container').find('.popup-body');
popupContent.addClass('show-popup');
})
$(document).on('click', '.page-content', function(e) {
if ( !e.target.classList.contains(".popup-body") ) {
$(".popup-body").removeClass('show-popup');
}
});
}
CSS
.popup-container {
position: relative;
display: inline-block;
background: none;
cursor: pointer;
}
.popup-container .popup-body {
visibility: hidden;
position: absolute;
width: 676px;
background-color: $color-white;
color: #000;
text-align: left;
padding: 30px;
z-index: 1;
opacity: 0;
transition: opacity 0.3s;
-webkit-box-shadow: 0px 2px 4px 0 rgba(0, 0, 0, 0.5);
-moz-box-shadow: 0px 2px 4px 0 rgba(0, 0, 0, 0.5);
box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.5);
}
.popup-container .show-popup {
visibility: visible;
opacity: 1;
@include susy-breakpoint(0 $breakpoint-tablet-landscape, 8) {
width: 350px;
}
}
.popup-bottom {
top: 135%;
left: 50%;
margin-left: -60px;
}
.popup-bottom::after {
content: "";
position: absolute;
display: block;
bottom: 100%;
left: 5%;
margin-left: -5px;
border-width: 0 10px 8px;
border-style: solid;
border-color: #fff transparent;
}
.popup-link {
color: $color-brand-1;
text-decoration: none;
font-weight: bold;
}
.popup-link:hover {
color: $color-link-hover;
text-decoration: none;
font-weight: bold;
}
我可能误会你了,但如果你只是想让 body 在它的位置离开时消失,为什么不在 that 元素上添加 mouseexit 函数反而?这是我所指的片段。
$(document).on('mouseenter click', '.popup-link', function() {
var popupContent = $(this).parent('.popup-container').find('.popup-body');
popupContent.addClass('show-popup');
})
$(document).on('mouseleave', '.popup-body', function() {
$(".popup-body").removeClass('show-popup');
})
$(document).on('click touch', function(e) {
if ( !e.target.classList.contains(".popup-body") ) {
$(".popup-body").removeClass('show-popup');
}
});
.popup-container {
position: relative;
display: inline-block;
background: none;
cursor: pointer;
}
.popup-container .popup-body {
visibility: hidden;
position: absolute;
width: 676px;
background-color: $color-white;
color: #000;
text-align: left;
padding: 30px;
z-index: 1;
opacity: 0;
transition: opacity 0.3s;
-webkit-box-shadow: 0px 2px 4px 0 rgba(0, 0, 0, 0.5);
-moz-box-shadow: 0px 2px 4px 0 rgba(0, 0, 0, 0.5);
box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.5);
}
.popup-container .show-popup {
visibility: visible;
opacity: 1;
@include susy-breakpoint(0 $breakpoint-tablet-landscape, 8) {
width: 350px;
}
}
.popup-bottom {
top: 135%;
left: 50%;
margin-left: -60px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="popup-container">
<span class="popup-link">Partner disclosure</span>
<span class="popup-body popup-bottom">
<h3>Partner relationships</h3>
<p>stuffs in popup body</p>
</span>
</div>
我正在尝试使用 javascript 和 css 创建自定义悬停。
一切正常,我可以切换 class 以显示和隐藏 popup/hover 气泡。 (弹出正文)
但是,我希望当光标悬停在气泡上时气泡也保持打开状态。 (弹出正文)
这会在离开弹出窗口后立即关闭-link,如果我在弹出窗口主体内呈现任何 link,悬停操作将变得无用。请帮忙!
HTML/ERB
<div class="popup-container">
<span class="popup-link">Partner disclosure</span>
<span class="popup-body popup-bottom">
<h3>Partner relationships</h3>
<p>stuffs in popup body</p>
</span>
</div>
Javascript
$(document).on('mouseleave click', '.popup-body', function() {
$(".popup-body").removeClass('show-popup');
})
### if mobile device
if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
$(document).on('click', '.popup-link', function() {
var popupContent = $(this).parent('.popup-container').find('.popup-body');
if (!popupContent.hasClass('show-popup')) {
popupContent.addClass('show-popup');
} else {
popupContent.removeClass('show-popup');
}
})
$(document).on('touchstart', '.page-content', function(e) {
if ( !e.target.classList.contains(".popup-body") ) {
$(".popup-body").removeClass('show-popup');
}
});
} else { ###desktop
$(document).on('mouseenter', '.popup-link', function() {
var popupContent = $(this).parent('.popup-container').find('.popup-body');
popupContent.addClass('show-popup');
})
$(document).on('click', '.page-content', function(e) {
if ( !e.target.classList.contains(".popup-body") ) {
$(".popup-body").removeClass('show-popup');
}
});
}
CSS
.popup-container {
position: relative;
display: inline-block;
background: none;
cursor: pointer;
}
.popup-container .popup-body {
visibility: hidden;
position: absolute;
width: 676px;
background-color: $color-white;
color: #000;
text-align: left;
padding: 30px;
z-index: 1;
opacity: 0;
transition: opacity 0.3s;
-webkit-box-shadow: 0px 2px 4px 0 rgba(0, 0, 0, 0.5);
-moz-box-shadow: 0px 2px 4px 0 rgba(0, 0, 0, 0.5);
box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.5);
}
.popup-container .show-popup {
visibility: visible;
opacity: 1;
@include susy-breakpoint(0 $breakpoint-tablet-landscape, 8) {
width: 350px;
}
}
.popup-bottom {
top: 135%;
left: 50%;
margin-left: -60px;
}
.popup-bottom::after {
content: "";
position: absolute;
display: block;
bottom: 100%;
left: 5%;
margin-left: -5px;
border-width: 0 10px 8px;
border-style: solid;
border-color: #fff transparent;
}
.popup-link {
color: $color-brand-1;
text-decoration: none;
font-weight: bold;
}
.popup-link:hover {
color: $color-link-hover;
text-decoration: none;
font-weight: bold;
}
我可能误会你了,但如果你只是想让 body 在它的位置离开时消失,为什么不在 that 元素上添加 mouseexit 函数反而?这是我所指的片段。
$(document).on('mouseenter click', '.popup-link', function() {
var popupContent = $(this).parent('.popup-container').find('.popup-body');
popupContent.addClass('show-popup');
})
$(document).on('mouseleave', '.popup-body', function() {
$(".popup-body").removeClass('show-popup');
})
$(document).on('click touch', function(e) {
if ( !e.target.classList.contains(".popup-body") ) {
$(".popup-body").removeClass('show-popup');
}
});
.popup-container {
position: relative;
display: inline-block;
background: none;
cursor: pointer;
}
.popup-container .popup-body {
visibility: hidden;
position: absolute;
width: 676px;
background-color: $color-white;
color: #000;
text-align: left;
padding: 30px;
z-index: 1;
opacity: 0;
transition: opacity 0.3s;
-webkit-box-shadow: 0px 2px 4px 0 rgba(0, 0, 0, 0.5);
-moz-box-shadow: 0px 2px 4px 0 rgba(0, 0, 0, 0.5);
box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.5);
}
.popup-container .show-popup {
visibility: visible;
opacity: 1;
@include susy-breakpoint(0 $breakpoint-tablet-landscape, 8) {
width: 350px;
}
}
.popup-bottom {
top: 135%;
left: 50%;
margin-left: -60px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="popup-container">
<span class="popup-link">Partner disclosure</span>
<span class="popup-body popup-bottom">
<h3>Partner relationships</h3>
<p>stuffs in popup body</p>
</span>
</div>