找不到以下场景的逻辑:
一个循环中有六个帖子,每个帖子都有一个带有自定义字段的颜色值。当鼠标悬停在帖子的摘录之一上时,它应该将摘录的背景更改为使用自定义字段设置的颜色。
它正在工作,但将鼠标悬停在一个帖子上会显示每个帖子的隐藏颜色,而不仅仅是一个。
有什么方法可以将帖子 ID 存储在变量中,然后将该变量传递给 JQuery addClass/removeClass 函数?
谢谢你。
HTML:
<?php if( $2nd_query->have_posts() ) : ?>
<?php while( $2nd_query->have_posts() ) : $2nd_query->the_post(); ?>
<?php $display = get_field('color_setting');?>
<div class="threesome">
<div id="<?php echo $display ?>" class="indextitle_seethrou">
<h2 class="indextitle"><a href="<?php the_permalink() ?>" title=""><?php the_title(); ?></a></h2>
</div>
<?php
if ( has_post_thumbnail() ) {
the_post_thumbnail('featured_thumb');
} else {
} ?>
</div>
<?php endwhile; ?>
<?php else : ?>
然后我有这个Jquery:
$('.threesome').hover(function() {
$('.indextitle_seethrou').stop(true, true).fadeIn('fast');
}, function() {
$('.indextitle_seethrou').stop(true, true).fadeOut('fast');
});
显然,由于三人组类,上面的代码将不起作用。有什么方法可以在 JQuery 中获取 $display var,然后对其应用一些 css 吗?