2011-11-09 39 views
0

我在使用jQuery的悬停功能和Wordpress循环时遇到了问题。每次我悬停一张图片(有6张)时,它们都会褪色,而不仅仅是单张图片。请帮忙。jQuery在Wordpress中悬停:在淡出“默认”div时淡入暗处div

这里是我的代码:

<?php query_posts('showposts=6&cat=-4'); ?> 
<?php if (have_posts()) : ?> 
<?php while (have_posts()) : the_post(); if ($post->ID == $do_not_duplicate) continue; update_post_caches($posts); ?> 

<li class="show1"> 

<?php $thumb = get_post_meta($post->ID, 'thumb', true); ?> 

<a href="#" title="Permanent Link to <?php the_title_attribute(); ?>" class="show"><?php echo$thumb; ?></a> 

<div class="hide"> 

    <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2> 

    <?php the_excerpt(); ?> 

    <a class="view_project" href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">View Project »</a> 
</div> 
</li> 

和我的JavaScript

<script type="text/javascript"> 
$(function() { 
$('li.show1').children('.hide').hide(); 

$('li.show1').hover(function() { 
    $(this).children('a.show').fadeOut('slow') 
     .end().children('.hide').fadeIn('slow'); 
}, function() { 
    $(this).children('a.show').fadeIn('slow') 
     .end().children('.hide').fadeOut('slow'); 
}); 
}); 
</script> 

谢谢你们。

回答

0

$('a.show')替换为$(this).children('a.show') - 这会将您的淡出限制在li内的锚定链接上,这些链接被悬停。

+0

非常感谢。现在只有一个被选中,但淡入和淡出效果不起作用,有什么建议? – Mauricio

+0

难道是因为你的'hover'回调函数是相同的,而不是相互的? – Blazemonger

+0

我也这么认为,但我改变了它(上面编辑),什么也没有发生。 – Mauricio