您的 HTML 和 CSS 存在一些问题。一方面,您有多个具有相同id
值的元素。您可能应该将这些切换到类,或者id
为每个元素创建一个唯一值。在您的 CSS 中,您是可能不需要浮动的浮动元素……并且您正在将内联样式与外部 CSS 混合。这不完全是一个问题,但在尝试进行故障排除时可能会让人头疼。
您的.hover
事件也会出现一些不稳定的行为,因为在动画序列完成之前事件可能会触发多次。
这是一个工作示例:http: //jsfiddle.net/kbgsP/11/
HTML:
<div class="tile">
<div class="main">
<img src="http://placehold.it/509x188" width="509" height="188" alt="roboform">
</div>
<div id="boo" class="second">
<p class="description"> <b>Roboform Bot</b>
<br>This bot will speed up the addition process of new idetities. All the identities will match to a fake Italian person. If you don't know the usage of Roboform like to know that it's a software that fill registration fields for you. The trial version lasts for one day only. The full version is priced 4€.</p>
<div class="LinkButton" onclick="location.href='http://www.fillobottosw.altervista.org/apps/roboform/Roboform_Bot.exe';"></div>
</div>
</div>
<div class="tile">
<div class="main">
<img src="http://placehold.it/509x188" width="509" height="188" alt="roboform">
</div>
<div id="boo" class="second">
<p class="description"> <b>Roboform Bot</b>
<br>This bot will speed up the addition process of new idetities. All the identities will match to a fake Italian person. If you don't know the usage of Roboform like to know that it's a software that fill registration fields for you. The trial version lasts for one day only. The full version is priced 4€.</p>
<div class="LinkButton" onclick="location.href='http://www.fillobottosw.altervista.org/apps/roboform/Roboform_Bot.exe';"></div>
</div>
</div>
CSS:
.tile {
overflow:hidden;
border:1px solid #999;
height: 188px;
width: 509px;
margin: 4px auto 12px auto;
cursor: pointer;
}
.main, .second {float:left; width:509px;}
.second {margin-left: 12px;}
.second p {color: #999;}
JS:
// hide your descriptions
$('.description').hide();
// track whether or not the user really wants to see the description
var checkIntent = '';
// how long should the user have to hover before you show them the description (in milliseconds)
var waitTime = 500;
// bind the hover event to all `.tile` elements.
$('.tile').hover(showDescription, hideDescription);
function showDescription(e){
// wait X seconds before starting the animation sequence
checkIntent = setTimeout(function() {
var tile = $(e.currentTarget);
var descriptionContainer = tile.find('.description');
descriptionContainer.data('showing', true);
tile.animate({width:'1100px'}, 300, function(){
descriptionContainer.fadeIn(300);
});
}, waitTime);
}
function hideDescription(e){
// if the user's mouse leaves the bound element and the timer has not fired,
// cancel the animation sequence to show the description
clearTimeout(checkIntent);
var tile = $(e.currentTarget);
var descriptionContainer = tile.find('.description');
// if the description is showing - hide it
if(descriptionContainer.data('showing')) {
descriptionContainer.fadeOut(300, function(){
tile.animate({width:'509px'}, 300);
});
descriptionContainer.data('showing',false);
}
}