【发布时间】:2015-02-21 07:50:31
【问题描述】:
我整理了一个示例来帮助解释这个问题:http://codepen.io/tathianactn/pen/EaEzRB。
在这个例子中,我有一个地图和地图上的各种标记(蓝色方块)。当您将鼠标悬停在标记上时,应该会出现一个带有图像(左)和一些文本(右)的工具提示。图像和文本 div 应该始终具有相同的高度,因此我使用 javascript 来确定最高的 div,并将该高度值分配给较短的 div。
最初,工具提示 div 被标记为“display: none;”,然后当您将鼠标悬停在标记上时它会“淡入”,当您将鼠标悬停在标记上时它会“淡出”。
我已经逐步测试了这段代码,并且在我添加淡入/淡出动作之前一切正常。在添加这两个动作之前,javascript 重新调整大小工作得很好(您可以尝试删除这两行来查看),但是当我添加这些淡入淡出动作时,高度停止正常工作。
我注意到,如果您快速将鼠标悬停在同一标记上,然后再将鼠标悬停在同一标记上,则高度调整大小确实会生效。
有什么想法吗?我在调整大小后添加了淡入淡出,假设所有调整大小都会在工具提示出现之前完成,但肯定有一些东西不能正常工作。
如果有任何帮助,我将不胜感激。谢谢!
$('a.map_marker').hover(function(e) {
//Change tooltip content based on location of marker clicked
var elementToGet = '.tooltip_html_source.'+$(this).attr('location');
var newHTML = $(elementToGet).html();
$('#tooltip_container .tooltip_content').html(newHTML);
//Get height of text div
var textHeight = $('#tooltip_container .tooltip_content .text').height();
//If text div is less than 70px (min height of image div)
if(textHeight < 70) {
//Then make the height of the text div = 70px
$('#tooltip_container .tooltip_content .text').height(70);
}
// else if the text div is greater than 70px
else if(textHeight > 70) {
//Make the height of the image div = the height of the text div
$('#tooltip_container .tooltip_content .image').height(textHeight);
}
//Once the resizing has been done, fade in the tooltip div
$('#tooltip_container').fadeIn('slow');
}, function() {
//On hover off, fade out the tooltip div
$('#tooltip_container').fadeOut('slow');
});
【问题讨论】:
标签: javascript jquery css fadein fadeout