我想做一個簡單的內容滑動thingy和卡住寫代碼可能是最簡單的東西 - 處理懸停滑塊的導航部分。我希望它是這樣的,當一個具有幻燈片信息的div被點擊時,懸停不起作用,但適用於其他兩個div。Mouseover/mouseout +:不是jQuery的問題
我已經嘗試過類和id的點擊div,但沒有任何作品,當我到達懸停部分。我試圖使用:不過濾選擇其他兩個div,或全部三個未被#clicked的。但是沒有太多的選擇 - 無論如何,懸停適用於所有三個div。我嘗試過使用:而不是像hide()這樣的其他函數,它工作得很好。那麼這是一個CSS特殊問題?或者是mouseover/mouseout有問題?或者對我來說,就像是一個無能的傻瓜?
這裏是我的html:
<div id="linkswrapper">
<div>
<a>Slide 1</a>
<p>Slide info 1.</p>
</div>
<div>
<a>Slide 2</a><p>Slide info 2.</p>
</div>
<div>
<a>Slide 3</a>
<p>Slide 3 info.</p>
</div>
</div>
這裏是jQuery代碼:
// adds href="#" to all links in "linkswrapper" div
$("#linkswrapper div a").attr({href: "#"});
// this handles clicks on the divs. When clicked, the div is assigned
// "clicked" id, and the id attribute is removed from the other sibling divs
$("#linkswrapper div").click(function() {
$(this).attr({id:"clicked"});
$("#linkswrapper div").not(this).each(function(){ $(this).removeAttr("id"); });
});
// handling the mouseover/mouseout. Hover should be working on all the three divs
// if neither of them has been clicked on or only on the two other divs if one
// of the three has been clicked on
$("#linkswrapper div:not(#clicked)").mouseover(function() {
$("a", this).css("border-color","#0066FF");
$("p", this).css("color","#0066FF");
}).mouseout(function(){
$("a", this).css("border-color","#e3e3e3");
$("p", this).css("color","#cccccc");
});