我的代码出了点问题,它的行为很奇怪。我写了一个代码,在悬停时,标题宽度将增加并适合容器宽度,我的代码它正在工作,但是如果你悬停并连续悬停,标题的宽度会增加并且不会恢复到默认宽度- 我知道令人困惑,所以我在这里给出代码......请帮助
HTML
<div class="cat-boxes">
<img src="img/3.jpg" />
<div class="cat-boxes-desc">
<span class="cat-title"><h3>culture and history</h3></span>
<p>
Festivals are true celebrations in God's Own Country
</p>
<a href="archive.html" class="articles">Articles</a>
</div>
</div><!--end cat-boxes-->
CSS
.cat-boxes{
width:300px;
overflow:hidden;
position:relative;
background:#ecebeb;
float:left;
margin-bottom:25px;
}
.cat-boxes img{
width:100%;
}
.cat-boxes-desc{
width:234px;
height:115px;
padding:6px 15px;
position:relative;
z-index:999;
background:rgba(255, 255, 255, .5);
margin: -25px auto 15px auto;
}
.cat-boxes-desc .cat-title{
display:inline-block;
padding:0 15px;
line-height:35px;
position:absolute;
top:-35px;
right:0;
background:#04a732;
}
.cat-boxes-desc .cat-title h3{
font-size:14px;
font-family:Arial, Helvetica, sans-serif;
line-height:35px;
text-align:center;
color:white;
text-transform:uppercase;
font-weight:normal;
margin:0;
}
.cat-boxes-desc p{
font: 14px Arial, Verdana, Geneva, sans-serif;
color:black;
line-height:20px;
text-transform:uppercase
}
jQuery
$(function(){
$('.cat-boxes').hover(function(){
$wd = $(this).find($('.cat-title')).width();
$(this).find($('.cat-title')).stop().animate({
top: '-35px',
right: '-20px',
width:'105%',
'text-align':'center'
}, {duration: "slow"});
}, function(){
$(this).find($('.cat-title')).stop().animate({
top: '-35px',
right: '0px',
width: $wd
}, {duration: "slow"});
});
});