文本和填充区域上的jQuery鼠标悬停不起作用

时间:2013-05-03 09:39:12

标签: jquery mouseover

我有一个wordpress博客,在循环中,布局就像左边的文本(标题。日期,摘要),图像是浮动到右边(填充50%左边),我想要50%的空间在左侧以及此处的所有元素(标题。日期,摘要)使其可以悬空(在悬停左侧区域时,将所有文本颜色更改为黑色,将背景更改为#ff7f00;)。

post-ut的CSS

  .post-ut {
    display:block;
    color:#999999; 
    z-index:2;
    float:left;
    letter-spacing:1px;
    font-size:13px;
    position: relative;
    width:282px;
}
.post-ut a {
    max-width:74px;
    min-width:74px;
    text-decoration:none;
    color: #999999;
    display:inline-block;
    z-index:1;
}

以下是我正在使用的jQuery代码的想法

    $('div.post-ut').mouseover(function() {


    $('.entry-summary p', $(this).parent())
       .css("color","black")
       .css("background","#ff7f00");

});

$('div.post-ut').mouseout(function() {

    $('.entry-summary p', $(this).parent())
       .css("color","white")
       .css("background","black");

});

wordress post loop的php代码是

<h1 class="thumb" style="z-index:2; width:252px;">
                    <a style="padding:15px 15px 5px 15px; width:252px; font-size:30px; font-weight:100; " href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', UT_THEME_NAME ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a>

                </h1>

               <br/>

                <div class="post-ut" style="margin-top:-43px;"> 
            &nbsp;&nbsp;&nbsp;&nbsp;<?php the_time('d. m. Y, g:i') ?> | <?php lambda_posted_in(); ?>                            
                </div> <!-- post by -->

            </header>

        <?php 

            echo '<div class="thumb" style="width:282px; padding-left:282px; margin-top:-114px; margin-bottom:20px; "><div class="post-image"><div class="overflow-hidden imagepost">';
            echo '<img class="wp-post-image"  style="display:inline-block; width:282px; height:272px;" src="'.$url.'" />';
            echo '<a title="'.get_the_title().'" href="'.get_permalink().'"><div class="hover-overlay"><span class="circle-hover"><img src="'.get_template_directory_uri().'/images/circle-hover.png" alt="'.__('link icon',UT_THEME_INITIAL).'" /></span></div></a>';
            echo '</div></div></div>';

        endif; ?>

        <div class="entry-content clearfix">



        <div class="entry-summary">

            <?php if ( is_archive() || is_search() || get_option_tree('excerpt_blog') == 'yes') : 

                the_excerpt(); 

            else : 
         ?>
           <?php endif; ?>   

        </div><!-- .entry-summary -->

        </div><!-- .entry-content -->

我正在使用jquery悬停图片,这很好用,但不是我上面发布的代码。工作代码是

$('div.thumb').mouseover(function() {
$('a', $(this).parent())
   .css("color","black")
   .css("background","#ff7f00");

$('.post-ut', $(this).parent())
   .css("color","black")
   .css("background","#ff7f00")
   .find('a').css("color","black");

$('.entry-summary p', $(this).parent())
   .css("color","black")
   .css("background","#ff7f00");

});

$('div.thumb').mouseout(function() {

    $('a', $(this).parent())
       .css("color","white")
       .css("background","black");

    $('.post-ut', $(this).parent())
       .css("color","white")
       .css("background","black")
       .find('a').css("color","white");

    $('.entry-summary p', $(this).parent())
       .css("color","white")
       .css("background","black");

});

更新:删除职位后:相对;从类post-ut开始,悬停工作但文本不可见

1 个答案:

答案 0 :(得分:0)

从代码中删除p并检查。

$('div.post-ut').mouseover(function() {

$('.entry-summary', $(this).parent())
   .css("color","black")
   .css("background","#ff7f00");

});

$('div.post-ut').mouseout(function() {

$('.entry-summary', $(this).parent())
   .css("color","white")
   .css("background","black");

});