【发布时间】:2013-10-03 22:46:14
【问题描述】:
当鼠标悬停在一个 div 上时,我想用另一个 div 替换它。具体来说会有一个平均的话,比如“苦苦挣扎”或者“超出预期”,我想当用户将鼠标悬停在平均的话上时用数值平均代替。
#html
<div class="switch avg_words float_left">
A+ (hover to see score)
</div>
<div class="avg_num">
AVG = 98.35%
</div>
#css
.avg_num {
display: none;
}
#jquery
$('.switch').hover(function() {
$(this).closest('.avg_words').hide();
$(this).next('div').closest('.avg_num').show();
}, function() {
$(this).next('div').closest('.avg_num').hide();
$(this).closest('.avg_words').show();
});
隐藏第一个 div 并用第二个替换它很容易,但问题在于当悬停结束时将其恢复正常的代码。现在悬停时,divs 只是在彼此之间来回闪烁。
【问题讨论】:
-
你怎么能只用 CSS 做到这一点?有什么好的资源吗?
-
接受的答案是最好和最简单的方法,我认为
-
我还是管理了:jsbin.com/nazase/3/edit?html,css,output。欢迎任何建议
-
哇,这是一个非常漂亮的解决方案,做得很好!
标签: jquery html hover dom-manipulation