首先,元素 ID 是唯一的,您只能在有效文档中拥有它们一次。所以我将id="name" 的所有实例更改为class="name",并将id="small" 的所有实例更改为class="small。
其次,我使用setTimeout() 和clearTimeout() 的组合来创建所需的延迟,但没有“链接”延迟。
最后,slideToggle()(以及相关的slideUp 和slideDown)似乎引起了问题,因此我将其替换为fadeIn() 和fadeOut()。我相信这会产生预期的行为,但如果不是,请告诉我。
HTML
<table class="listings">
<thead>
<tr>
<th class="star"><span title="Save listing to favorites">☆</span></th>
<th colspan="3">Description</th>
<th colspan="2">Text</th>
</tr>
</thead>
<tbody>
<tr>
<td class="star"><span title="Save listing to favorites">☆</span></td>
<td class="name" colspan="3">Hover over me for more info.
<span class="collapsed">Here is some hovered over text.</span>
</td>
<td class="small" colspan="2">Here is additional text.</td>
</tr>
<tr>
<td class="star"><span title="Save listing to favorites">☆</span></td>
<td class="name" colspan="3">Hover over me for more info.
<span class="collapsed">Here is some hovered over text.</span>
</td>
<td class="small" colspan="2">Here is additional text.</td>
</tr>
<tr>
<td class="star"><span title="Save listing to favorites">☆</span></td>
<td class="name" colspan="3">Hover over me for more info.
<span class="collapsed">Here is some hovered over text.</span>
</td>
<td class="small" colspan="2">Here is additional text.</td>
</tr>
</tbody>
</table>
CSS(只是一个小改动以反映从 ids 到类的变化)
div.left-and-right {
margin-left:auto;
margin-right:auto;
position:relative;
margin-top:5%;
width:90%;
min-height:300px;
}
.listings {
width:100%;
border-collapse:collapse;
border:1px solid #E18728;
font-size:1em;
}
.listings td {
padding:5px 10px;
text-align:left;
}
.listings th {
padding:5px 10px;
margin:0px 10px;
background-color:#E18728;
text-align:left;
}
.listings tr:nth-child(odd) {
background-color:#F6F6F6;
border-top:1px solid #EAE8E8;
border-bottom:1px solid #EAE8E8;
}
td.small {
font-size:0.8em;
padding-top:8px;
vertical-align:top;
}
.star {
padding:5px;
margin:0px;
}
.collapsed{
display:block;
margin-top:40px;
}
Javascript
var timeoutID;
$(document).ready(function(){
$('.collapsed').hide();
$("td.name").hover(
function(){
thisThing = $(this);
timeoutID = setTimeout(function(thisThingHere){
thisThingHere.children('.collapsed').fadeIn(100);
}, 500, thisThing);},
function(){
clearTimeout(timeoutID);
$(this).children('.collapsed').fadeOut(100);
}
);
});
DEMO