gpt4 book ai didi

javascript - CSS悬停卡片定位

转载 作者:技术小花猫 更新时间:2023-10-29 12:02:05 26 4
gpt4 key购买 nike

我正在尝试使用 css 制作悬停卡片。我有一个关于页面向下位置的问题。

我创建了这个 DEMO 来自 codepen.io 的页面。因此,如果您位于演示页面的底部,那么您会看到气泡 div 出现。

我应该怎么做才能在页面下方的三 Angular 形底部显示 .bubbleenter image description here

.container{
width:400px;
height:400px;
margin:0px auto;
margin-top:50px;
}
.bubble
{
position: absolute;
width: 250px;
height: 120px;
padding: 0px;
background: #000;
-webkit-border-radius: 2px;
-moz-border-radius: 2px;
border-radius: 2px;
display:none;
}

.bubble:after
{
content: '';
position: absolute;
border-style: solid;
border-width: 0 15px 15px;
border-color: #000 transparent;
display: block;
width: 0;
z-index: 1;
top: -15px;
left: 194px;
}
.hub:hover .bubble{
display:block;
}
.wrp{
width:300px;
height:68px;
}

最佳答案

编辑

I have made a jQuery plugin that addresses this issues, repositions the tooltip to stay inside window, simple & responsive. You can see it in action here tipso

我 fork 你的 codepen 并修改了它 on codepen

我想这就是您要找的:)

$('.hub').on({
mouseenter: function() {
$(this).addClass('zIndex');

var top, left,
toolTipWidth = 250,
toolTipHeight = 120,
arrowHeight = 15,
elementHeight = $(this).height(),
elementWidth = $(this).width(),
documentHeight = $(window).height(),
bounding = $(this)[0].getBoundingClientRect(),
topHub = bounding.top;


if (topHub < topHub + toolTipHeight && topHub + toolTipHeight + arrowHeight + elementHeight <= documentHeight) {

$('.bubble').addClass('top');
top = elementHeight + arrowHeight;
left = -(elementWidth / 2);

}

if (topHub + toolTipHeight + arrowHeight + elementHeight >= documentHeight) {
$('.bubble').addClass('bottom');
top = -toolTipHeight - arrowHeight;
left = -(elementWidth / 2);
}


$('.bubble').css({
'top': top,
'left': left
});
},
mouseleave: function() {
$('.bubble').removeClass('top bottom');
$(this).removeClass('zIndex');
}
});

关于javascript - CSS悬停卡片定位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26822445/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com