我有兩個divs
,懸停span class=fg
增長和更改不透明度,span class=bg
收縮,當你mouseout
它回到原來的狀態。jquery targeting /懸停問題
我的問題是兩個部分:
1:當鼠標懸停在第一個div,同樣的動作發生在第二位。
2:懸停不限於div,但只要鼠標在頁面上移動就會發生。
HTML:
<div id="wrap">
<h2>Subtitle</h2>
<p>
<span class="bg">Lorem Ipsum has been the</span>
<a href="#"><span class="fg"> industry’s standard</span></a>
<span class="bg">dummy text ever</span>
<span class="fg">since the 1500s,</span>
span class="bg">when an unknown printer took a galley of type and</span>
</p>
</div>
<div id="wrap" class="">
<h2>Stuff #2</h2>
<p>
<span class="bg">Lorem Ipsum has been the</span>
<span class="fg"> industry’s standard</span>
<span class="bg">dummy text ever</span>
<span class="fg">since the 1500s,</span>
<span class="bg">when an unknown printer took a galley of type</span>
</p>
</div>
JavaScript的:
<script type="text/javascript">
$(document).ready(function() {
$("#wrap").parent().hover (function() {
$("span.fg").animate({"opacity": 1, fontSize: '14px'}, 300);
$("span.bg").animate({fontSize: '7px'}, 300);
},
function() {
$("span.fg").animate({"opacity": .5, fontSize: '12px'}, 100);
$("span.bg").animate({fontSize: '12px'}, 100);}
);
});
CSS:
body {background: #000;color: #FFF;font-family: Helvetica, sans-serif;}
p {font-size:12px;}
#wrap { width: 300px;
height: 150px;
cursor: pointer;
margin: 30px auto;
overflow:hidden;
}
a {text-decoration:none; color:inherit;}
.bg {color:#999; opacity: 0.4;}
.fg {color:#999; opacity: 0.4;}
你有兩個不同的'格'用相同的ID。不要使用這種方法。每個元素的ID應該是唯一的。 –
'$(「#wrap」)。parent()'body元素?我不確定是否粘貼了所有內容,但是如果是這樣的話,'hover'會應用到主體(即整個頁面)。 – pimvdb