我已经用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");
});
});
你应该尝试动画,而不是在这种情况下切换。第一个div会触发第二个div的动画。当用户将鼠标移出时,第二个div会触发。 – tintyethan
我同意@tintyethan。你应该看看jQuery [.stop()](https://api.jquery.com/stop/),特别是'.stop(true)',这样反复盘旋不会导致动画重复运行。 –