【发布时间】:2011-08-10 12:07:09
【问题描述】:
找不到以下场景的逻辑:
一个循环中有六个帖子,每个帖子都有一个带有自定义字段的颜色值。 当鼠标悬停在某个帖子的摘录上时,它应该将摘录的背景更改为使用自定义字段设置的颜色。
它正在工作,但将鼠标悬停在一个帖子上会显示每个帖子的隐藏颜色,而不仅仅是一个。
有什么方法可以将帖子 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 吗?
【问题讨论】:
-
一些代码会有所帮助。请发布一些示例代码。
标签: jquery wordpress hover addclass removeclass