0
我想triggger顯示/隱藏效果時,點擊我的頁面上的鏈接,我的網頁的安裝方式是,我有以下的HTML,的jQuery找到最接近元素點擊
<div class="results clearfix">
<div class="product">
<div class="media">
</div>
<div class="information">
<div class="name">A Product</div>
<a href="">€50</a>
</div>
</div>
<div class="product">
<div class="media">
</div>
<div class="information">
<div class="name">A Product</div>
<a href="">€50</a>
</div>
</div>
<div class="product">
<div class="media">
</div>
<div class="information">
<div class="name">A Product</div>
<a href="">€50</a>
</div>
</div>
<div class="product">
<div class="media">
</div>
<div class="information">
<div class="name">A Product</div>
<a href="">€50</a>
</div>
</div>
<div class="moreWrapper">
<div class="more">
<div class="arrow"></div>
<div class="media">
<img src="assets/css/img/more-image.jpg" />
<a class="view" href="">View item</a>
</div>
<div class="details">
<a class="cart" href="">€50</a>
<a class="bookmark" href=""></a>
<div class="clearfix"></div>
<div class="breakdown clearfix">
<h1>ÖRSJÖ BELYSNING PJ DESK LAMP</h1>
<small>Item Number : UL-1027</small>
<dl>
<dt>Manufacturer</dt>
<dd><img src="assets/img/alessi-logo.jpg"/></dd>
</dl>
<dl>
<dt>Created By</dt>
<dd>
<img src="assets/img/created.jpg" alt="" />
<strong>3d_alan</strong>
<span>on 27th Jan 2013</span>
</dd>
</dl>
<dl>
<dt>Method of creation</dt>
<dd>
<i class="creation icon-camera"></i>
<i class="creation icon-hands"></i>
<i class="creation icon-pencil"></i>
<i class="creation icon-fullscreen"></i>
<i class="creation icon-pencil"></i>
<i class="creation icon-photo"></i>
</dd>
</dl>
<dl>
<dt>Year of manufactuer</dt>
<dd>1990</dd>
</dl>
<p><em>Available Formats</em> <a href="">Require a different format?</a></p>
<ul class="formats">
<li>3DSMax</li>
<li>VRay</li>
</ul>
</div>
</div>
</div>
</div>
<div class="product">
<div class="media">
</div>
<div class="information">
<div class="name">A Product</div>
<a href="">€50</a>
</div>
</div>
<div class="product">
<div class="media">
</div>
<div class="information">
<div class="name">A Product</div>
<a href="">€50</a>
</div>
</div>
<div class="product">
<div class="media">
</div>
<div class="information">
<div class="name">A Product</div>
<a href="">€50</a>
</div>
</div>
<div class="product">
<div class="media">
</div>
<div class="information">
<div class="name">A Product</div>
<a href="">€50</a>
</div>
</div>
<div class="moreWrapper">
<div class="more"></div>
</div>
</div>
每一個後4 .product
元素有一個.moreWrapper
,然後再有4個.product
元素,然後是另一個.moreWrapper
。我努力實現的是讓最接近的點擊元素打開.moreWrapper
,目前全部打開.moreWrapper
。
這裏是我當前的javascript,
$(".product").click(function(e){
$(this).find("a").addClass("set");
var x = $(this).position().left;
$(this).parent().find('.moreWrapper').css("display", "none").animate({
"height" : "0px",
}, 1000);
$(this).parent().find('.moreWrapper').css("display", "block").animate({
"height" : "500px",
}, 1000);
$(".arrow").css("left", x+"px");
return false
});
最近的意思是「之前」或「之後」的單擊元素? – Alexander 2013-02-10 11:15:24
如果之前,然後使用'最接近()'。 – 2013-02-10 11:57:18