刚开始学习jQuery的 - 这里是我的问题:jQuery的 - 如何在同父的div元素仅作为目标触发事件的按钮
我有一个页面在六个div的。每个div都包含一个带类.arrow_trigger的链接和一个带类.arrow_tip的图像。这是HTML。
<div class="sixbox">
<img src="images/photos/box_6.jpg" width="280" height="180" alt="don´t stay in" class="leather_border">
<div class="wrap_arrow"><a href="what_we_do.html#report_design" class="arrow_trigger"><h2>Reports</h2></a></div>
<img src="images/buttons/blue_arrow_tip.png" width="41" height="47" alt="arrow_tip" class="arrow_tip">
<ul>
<li>Company reports</li>
<li>Datasheets</li>
<li>Corporate style development</li>
<li>Printed and delivered</li>
</ul>
</div><!-- end sixbox -->
我需要每个.arrow_trigger动画包含在同一个div中的.arrow_tip。我已经来达到的效果与下面的代码:
<script type="text/javascript">
$(document).ready(function() {
$('.arrow_trigger').hover(function() {
$(".arrow_tip").stop().animate({left:'190px'}, {queue:false,duration:200});
},
function() {
$(".arrow_tip").stop().animate({left: '184px'}, {queue: false, duration:200});
});
});
</script>
然而 - 这个代码,所有.arrow_tips正在有针对性的,而不只是一个在同一个父DIV的.arrow_trigger。
任何帮助非常感谢!
感谢您的建议,但这并没有奏效。动画(适用于我原始代码中的all.arrowtips)不适用于任何。我也试过.closest而不是.next,但仍然没有成功。我使用Jquery 1.5以防万一。 – nfrost21 2011-04-27 12:09:34
@Nick Frost:代码固定在答案中。也添加了工作示例。 – neebz 2011-04-27 12:36:08
太棒了 - 你为我节省了一大笔头痛。非常感谢。 – nfrost21 2011-04-27 13:20:45