我有下面的代碼應該切換一個div和一些p的背景,它不,我不明白爲什麼。你能幫忙嗎?jQuery懸停功能,切換不起作用
jQuery的
$(document).ready(function(){
$("div.portfolio-img").hover(
function(){
$(this).toggleClass(".portfolio-img-hover");
$(this).find("h5.excerpt-title").toggleClass(".excerpt-title-hover");
$(this).find("p.portfolio-excerpt").toggleClass(".portfolio-excerpt-hover");
}
)
});
HTML
<div class="portfolio-img">
<a href="#single_project"><img src="images/thumbnail.jpg"/></a>
<h5 class="excerpt-title">First Title</h5>
<p class="portfolio-excerpt">Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum</p>
</div>
CSS
h5.excerpt-title{
margin:30px 0px 5px;
transition:background-color 0.5s ease;
}
.excerpt-title-hover{
opacity:1;
color: #ed0b0b;
}
.portfolio-excerpt-hover{
opacity:1;
background:#e2e2e2;
}
.portfolio-img-hover{
opacity:1;
background:#e2e2e2;
border-bottom:2px solid #ed0b0b;
}
.portfolio-img{
width:220px;
display:inline-block;
padding:15px 5px;
margin:0px 5px 10px;
opacity:0.6;
border-bottom:1px solid grey;
transition:background-color 0.5s ease;
background-color:#ffffff;
}
的jsfiddle這裏:http://jsfiddle.net/a12b0u0k/
A)您需要刪除標記,在切換類功能點。 B)你需要在查找功能中添加點:http://jsfiddle.net/a12b0u0k/1/ – 2014-09-23 20:47:57