滑动面板在鼠标悬停时振荡
Sliding panel oscillates while mouse over
我用HTML和jQuery构建了一个div容器,当您将鼠标悬停在它上面时,另一个面板会在顶部滑动。但我正在体验滑动面板的"yoyo"。我认为这是因为当面板在div上滑动时,悬停状态会被触发,然后丢失,因此面板会不断地上下弹出。
我想发生的是,当你在广场上的任何地方悬停时,面板会显示,而当你不在广场上时,面板不会显示。
这是一把小提琴,这样你就可以看到问题是什么,也许这样解释更容易。
https://jsfiddle.net/xa5gtd2u/3/
这里还有代码
HTML
<div class="container">
<div class="services-blocks">
<img class="alignnone size-full wp-image-1974" src="http://placehold.it/250x250" alt="Design" width="250" height="250" />
<h3>title here</h3>
</div>
<div class="services-slide-panel">
<h3>title here</h3>
Some text here
Some text here
Some text here
Some text here
</div>
</div>
CSS
.services-slide-panel {
background: #f3535e;
width: 100%;
position: absolute;
left: 0;
bottom: 0;
top: 0;
display: none;
color: #ffffff;
}
.services-slide-panel h3 {
color: #ffffff;
}
.services-blocks h3 {
text-align: center;
position: absolute;
bottom: 5%;
width: 100%;
color: #ffffff;
}
.container {
width: 250px;
height: 250px;
position: relative;
}
jQuery
$(document).ready(function() {
$(".services-blocks").hover(function() {
$(this).next(".services-slide-panel").slideToggle("slow");
});
});
CSS3转换总是实现此类效果的更好选择。此外,您必须在.container
上hover()
,否则滑动的div将代替悬停,并调用hover()
函数的悬停部分。
$(document).ready(function() {
$(".container").hover(function() {
$(this).find(".services-slide-panel").addClass("slow");
}, function() {
$(this).find(".services-slide-panel").removeClass("slow");
});
});
.services-slide-panel {
background: #f3535e;
width: 100%;
position: absolute;
left: 0;
bottom: 0;
top: 110%;
color: #ffffff;
transition: all 0.3s ease;
}
.services-slide-panel.slow {
top: 0%;
}
.services-slide-panel h3 {
color: #ffffff;
}
.services-blocks h3 {
text-align: center;
position: absolute;
bottom: 5%;
width: 100%;
color: #ffffff;
}
.container {
width: 250px;
height: 250px;
position: relative;
overflow:hidden;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container">
<div class="services-blocks">
<img class="alignnone size-full wp-image-1974" src="http://placehold.it/250x250" alt="Design" width="250" height="250" />
<h3>title here</h3>
</div>
<div class="services-slide-panel">
<h3>title here</h3> Some text here Some text here Some text here Some text here
</div>
</div>
Fiddle here
相关文章:
- 当鼠标悬停在文本中的单词上时显示警报
- d3.js鼠标悬停鼠标输出问题
- 悬停(鼠标离开)方法不显示效果
- 为什么addEventListener只执行我的函数,而不为其创建鼠标悬停/鼠标打开事件
- 在鼠标悬停/鼠标出类中的任何元素时更改元素 ID
- 检测鼠标悬停/鼠标单击,无论 Z 顺序/图层级别如何
- 悬停/鼠标悬停功能冲突
- 子元素的 JavaScript 鼠标悬停/鼠标退出问题
- 在 iPad 上触发悬停/鼠标退出/模糊
- 如何通过按钮单击和鼠标悬停/鼠标退出显示和隐藏节点文本?D3/JS.
- 背景图像在悬停/鼠标悬停时消失,菜单在IE中不起作用
- jQuery鼠标悬停/鼠标悬停将不适用于Live
- jQuery-悬停以在刷新时触发悬停/鼠标悬停
- 悬停/鼠标悬停未在元素内部的每次移动中激活
- HighCharts条形图:悬停鼠标时显示条形值
- 鼠标悬停/鼠标离开,鼠标进入/鼠标离开,鼠标悬停闪烁问题
- 滚动时未触发鼠标悬停/鼠标输入
- JavaScript-如何在鼠标悬停/鼠标悬停上同时更改TR中所有TD的背景颜色
- 记住并在悬停鼠标悬停后显示以前活动的导航选项卡
- JavaScript延迟CSS悬停/鼠标悬停效果