爲什麼這項工作:jQuery的:選擇不一致,可有人請解釋我在做什麼錯在這裏
$("div.cat_rollout").mouseover(function(){
$(this).removeClass().addClass("cat_rollover");
$(this).animate({ fontSize: "22px" }, 'fast');
}).mouseout(function(){
$(this).removeClass().addClass("cat_rollout");
$(this).animate({ fontSize: "10px" }, 'fast');
});
但這並不:
$('.vpMedia').click(function() {
var selectedBT1 = $(this).find(".vpLeft");
selectedBT1.removeClass();
selectedBT1.addClass("vpLeft_Selected"); //doesn't work
var selectedBT2 = $(this).find(".vpLeftText");
selectedBT2.removeClass();
selectedBT2.addClass("vpLeftText_Selected"); //doesn't work
$(this).find(".vpArrow").css("visibility", "visible"); //works
});
唯一的區別是,我」通過查找引用孩子。
如果我做上面的代碼,但變化:
var selectedBT2 = $(this).find(".vpLeftText");
selectedBT2.removeClass();
selectedBT2.addClass("vpLeftText_Selected");
要只是改變CSS:
var selectedBT2 = $(this).find(".vpLeftText");
selectedBT2.css("color", "#f00");
它的工作原理。因此,有話跟我做一個雙重的jQuery(removeClass和addClass)
下面是一些HTML:
<div class="vpWrapper">
<div class="vpMedia">
<a href="1.mp4" bitly="BITLY_PROCESSED">
<div class="vpArrow" style="visibility: visible; ">
<img src="vpArrow.png" width="12" height="14">
</div>
<div class="vpLeftWrapper">
<div class="vpLeftText_Selected">Blah</div>
<div class="vpLeft_Selected"></div>
</div>
<div class="vpRight">
<div class="vpRightImg">
<img src="1-preview.png" width="137" height="77">
</div>
</div>
</a>
</div>
<div class="vpMedia">
<a href="2.jpg" bitly="BITLY_PROCESSED">
<div class="vpArrow">
<img src="vpArrow.png" width="12" height="14">
</div>
<div class="vpLeftWrapper">
<div class="vpLeftText" style="color: rgb(170, 170, 170); ">Blah</div>
<div class="vpLeft" style="opacity: 0; "></div>
</div>
<div class="vpRight">
<div class="vpRightImg">
<img src="2-preview.png" width="137" height="77">
</div>
</div>
</a>
</div>
<div class="vpMedia">
<a href="3.jpg" bitly="BITLY_PROCESSED">
<div class="vpArrow" style="visibility: visible; ">
<img src="vpArrow.png" width="12" height="14">
</div>
<div class="vpLeftWrapper">
<div class="vpLeftText_Selected" style="color: rgb(0, 204, 0); ">Blah</div>
<div class="vpLeft_Selected" style="opacity: 0.2; "></div>
</div>
<div class="vpRight">
<div class="vpRightImg">
<img src="3-preview.png" width="137" height="77">
</div>
</div>
</a>
</div>
<div class="vpMedia">
<a href="4.jpg" bitly="BITLY_PROCESSED">
<div class="vpArrow">
<img src="vpArrow.png" width="12" height="14">
</div>
<div class="vpLeftWrapper">
<div class="vpLeftText">Blah</div>
<div class="vpLeft"></div>
</div>
<div class="vpRight">
<div class="vpRightImg">
<img src="4-preview.png" width="137" height="77">
</div>
</div>
</a>
</div>
<div class="vpMedia">
<a href="5.jpg" bitly="BITLY_PROCESSED">
<div class="vpArrow">
<img src="vpArrow.png" width="12" height="14">
</div>
<div class="vpLeftWrapper">
<div class="vpLeftText">Blah</div>
<div class="vpLeft"></div>
</div>
<div class="vpRight">
<div class="vpRightImg">
<img src="5-preview.png" width="137" height="77">
</div>
</div>
</a>
</div>
<div class="vpMedia">
<a href="6.jpg" bitly="BITLY_PROCESSED">
<div class="vpArrow">
<img src="vpArrow.png" width="12" height="14">
</div>
<div class="vpLeftWrapper">
<div class="vpLeftText">Blah</div>
<div class="vpLeft"></div>
</div>
<div class="vpRight">
<div class="vpRightImg">
<img src="6-preview.png" width="137" height="77">
</div>
</div>
</a>
</div>
<div class="vpMedia">
<a href="7.jpg" bitly="BITLY_PROCESSED">
<div class="vpArrow">
<img src="vpArrow.png" width="12" height="14">
</div>
<div class="vpLeftWrapper">
<div class="vpLeftText">Blah</div>
<div class="vpLeft"></div>
</div>
<div class="vpRight">
<div class="vpRightImg">
<img src="7-preview.png" width="137" height="77">
</div>
</div>
</a>
</div>
</div>
編輯:按照要求,CSS
.vpWrapper {
width:286px;
overflow-x: visible;
}
.vpMedia {
margin: 0;
padding: 0;
background-color: fuchsia;
}
.vpArrow {
height: 69px;
width:12px;
padding-top: 8px;
float: left;
visibility: hidden;
}
.vpLeftWrapper {
position: relative;
float: left;
background-color: white;
width:137px;
height: 77px;
}
.vpLeft {
position: absolute;
top:0;
left: 0;
z-index: 788;
float: left;
background-color: #00cc00;
width:121px;
height: 61px;
padding: 8px;
-moz-opacity:0;
-ms-filter:'alpha(opacity=0)';
filter:alpha(opacity=0);
opacity:0;
}
.vpLeft_Selected {
position: absolute;
top:0;
left: 0;
z-index: 788;
float: left;
background-color: #00cc00;
width:121px;
height: 61px;
padding: 8px;
}
.vpLeftText {
position: absolute;
top:0;
left: 0;
z-index: 789;
width:121px;
height: 61px;
padding: 8px;
}
.vpLeftText_Selected {
position: absolute;
top:0;
left: 0;
z-index: 789;
width:121px;
height: 61px;
padding: 8px;
color: white;
}
你可以張貼一些HTML? – hunter 2010-07-29 16:43:08
另外,請解釋什麼「不工作」需要:) – 2010-07-29 17:13:58
哈哈,以及它不會刪除類,然後添加新的類。 它確實刪除它,如果我只是說這(如第一個代碼示例中看到的),但它的下一個樣品中不(僅僅是因爲我問了jQuery .find()內$的東西(這))。 我真的不明白!我的意思是爲什麼不呢。很好理解爲什麼它不起作用。 – RGBK 2010-07-29 17:22:32