jQuery选择器嵌套在几个DIV和PHP代码中

时间:2014-12-11 04:35:40

标签: javascript php jquery html css

我正在尝试将jquery悬停效果添加到我网站上的图像中,我希望图像在鼠标悬停时变得不透明,并在鼠标输出时变回完全不透明。我遇到的问题是PHP正在我的页面上填充图像,我不知道用什么选择器来获得我想要的效果。

这是HTML

<div id='gridcontainer'>

<?php
$counter = 1; //start counter
$grids = 2; //Grids per row
global $query_string; //Need this to make pagination work
 /*Setting up our custom query (In here we are setting it to show 12 posts per page and eliminate all sticky posts*/
query_posts($query_string . '&caller_get_posts=1&posts_per_page=12');
if(have_posts()) :  while(have_posts()) :  the_post();
?>
<?php
//Show the left hand side column
if($counter == 1) :
?>
            <div class="griditemleft">
                <div class="postimage">
                        <?php the_content('Read the rest of this entry &raquo;'); ?>
                </div>
            </div>
<?php
//Show the right hand side column
elseif($counter == $grids) :
?>
<div class="griditemright">
                <div class="postimage">
                        <?php the_content('Read the rest of this entry &raquo;'); ?>
                </div>
            </div>
<?php
$counter = 0;
endif;
?>
<?php
$counter++;
endwhile;
endif;
?>


</div>

这就是HTML如何在FIREBUG中显示(显示图像标记)

<div id="gridcontainer">
<div class="griditemleft">
<div class="postimage">
<p>
<a href="http://margierodrigues.com/taliecarterbeauty/wp-content/uploads/2014/12/lash_3.gif">
<img class="alignnone size-medium wp-image-108" width="300" height="300" alt="lash_3" src="http://margierodrigues.com/taliecarterbeauty/wp-content/uploads/2014/12/lash_3-300x300.gif">
</a>
</p>
</div>

任何人都可以提供任何见解吗?

2 个答案:

答案 0 :(得分:0)

有很多方法可以做,你可以有两个不同的不透明度的类,或者你可以在jQuery中使用animate功能。

我使用toogling类创建了example,而animate示例位于jquery animate docs

答案 1 :(得分:0)

尝试使用$('.postimage img')选择器。这应该应用您设置为postimage div。

中包含的img标记的任何所需效果