gpt4 book ai didi

css - 无法阻止 :hover from repeatedly firing

转载 作者:太空宇宙 更新时间:2023-11-04 05:57:48 25 4
gpt4 key购买 nike

我有以下代码。当用户将鼠标悬停在 div 上时,它应该下降并保持这种状态,直到用户将鼠标悬停在 div 上。在 div 上时,即使您稍微移动鼠标,悬停 Action 也会继续触发。

html

<div class="whitelabelfeatures">
<div class="box1 requirements responsibilities">
<div class="responsibilitiesbox">
<div class="responsibility">
<div class="section1">
Pricing
</div>
<div class="section1a">
Pricing test
</div>
</div>
</div>
</div>
</div>

CSS

.box1.requirements.responsibilities {
height: 300px;
overflow: hidden;
}

.responsibility .section1 {
background-color: #c2bbb1;
height: 300px;
color: white;
font-weight: 700;
position: relative;
z-index: 2;
transition: all .3s ease;
}

.responsibility .section1:hover {
transform: translateY(300px);
}

.responsibility .section1a {
position: absolute;
z-index: 1;
top: 0;
}

代码笔

https://codepen.io/jasonhoward64/pen/YzKNxVN

谢谢!

最佳答案

您可以在此处使用 javascript。请看下面的代码。

var targetDiv = document.getElementsByClassName("section1")[0];

targetDiv.addEventListener('mouseenter', function(){
targetDiv.classList.add('section1mouseover');
});

var testDiv = document.getElementsByClassName("section1a")[0];

testDiv.addEventListener('mouseenter', function(){
targetDiv.classList.remove('section1mouseover');
});
.box1.requirements.responsibilities {
height: 300px;
overflow: hidden;
}

.responsibility .section1 {
background-color: #c2bbb1;
height: 300px;
color: white;
font-weight: 700;
position: relative;
z-index: 2;
transition: all .3s ease;
}

.section1mouseover {
transform: translateY(300px);
}

.responsibility .section1a {
position: absolute;
z-index: 1;
top: 0;
}
<div class="whitelabelfeatures">
<div class="box1 requirements responsibilities">
<div class="responsibilitiesbox">
<div class="responsibility">
<div class="section1">
Pricing
</div>
<div class="section1a">
Pricing test
</div>
</div>
</div>
</div>
</div>

关于css - 无法阻止 :hover from repeatedly firing,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57619542/

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