当上面的图像div上的图像悬停时,如何更改下面的标题div上的背景图像?

时间:2012-04-07 14:58:27

标签: jquery css html rollover

我有这些称为“列”的div块,其中每列div包含单独的两个div(顶部和底部) - 一个div用于“图像占位符”,另一个div用于“caption”。现在,当我将鼠标悬停在占位符div上的图像上时,我希望触发操作应用于图像,然后它还将更改标题div上的背景图像。标题div在CSS中应用了背景图像精灵,其中“活动”状态位于0,0位置,“悬停状态位于底部位置。”

问题是我编写和试验的Jquery代码,不起作用:

$('.products2 .thumbnail .holder .image a').bind('mouseover', function(){ $('.products2 .thumbnail .holder .caption').css("background-position", "0 -91px");});

这是HTML标记:

<div class="products2">
      <div class="thumbnail" >
           <div class="holder">
              <div class="image"><a href="?page_id=185"><img src="<?php echo get_bloginfo('template_directory'); ?>/images/embellishments-image.jpg" alt="Embellishments" width="253" height="318"/></a></div>
              <div class="caption"><a href="?page_id=185">Embellishments</a></div>
          </div>
      </div>
 </div>

这是CSS:

.page-wrapper .products2 .thumbnail .caption{
    width:253px; height:86px; background: url(images/thumb-caption-sprite.jpg) no-repeat;
    color: #426e94; text-align: center;font-size:25px; text-decoration: none; font: 22px 'LiberationSerifRegular', Arial, sans-serif; padding-top:5px; outline: none; position: relative;z-index:2;position: absolute;display: table;

}

.page-wrapper .products2 .thumbnail .caption .hover{
    background: url(images/thumb-caption-sprite.jpg) no-repeat;
    background-position: 0 -91px;
    display:block;
    opacity: 0; z-index: -1;
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    width: 100%;
    cursor: pointer;color: #FFFFFF;text-shadow: none;
}

.page-wrapper .products2 .thumbnail .caption:hover{
    width:253px; height:86px; background: url(images/thumb-caption-sprite.jpg) no-repeat; color: #FFFFFF;
    background-position: 0 -91px;text-shadow: none;
}

1 个答案:

答案 0 :(得分:1)

请注意我完全理解你想要的东西,但如果我没弄错的话:

.image:hover + .caption
{
    background-position: 0 -91px;
}

如果我错了,请提供一个小提琴。