简体   繁体   English

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

[英]jQuery selectors nested within several DIVs and PHP code

I am trying to add a jquery hover effect to the images on my site, i would like the image to become opaque on mouseover, and back to full opacity on mouseout. 我正在尝试向网站上的图像添加jquery悬停效果,我希望图像在鼠标悬停时变得不透明,并在鼠标悬停时恢复为完全不透明。 The problem that i am encountering is that the images are being populated on my page by PHP and i do not know what selector to use to get the effect that i want. 我遇到的问题是图像是由PHP填充在我的页面上的,我不知道该使用哪个选择器来获得想要的效果。

Here is the HTML 这是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>

AND THIS IS HOW THE HTML SHOWS UP IN FIREBUG (SHOWS THE IMAGE TAGS) 这就是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>

can anyone offer any insight? 谁能提供任何见解?

There are quite a few ways to do it, you can have two classes with different opacity or you could use the animate functionality in jQuery. 有很多方法可以做到,您可以使两个类具有不同的不透明度,或者可以在jQuery中使用animate功能。

I made an example , using the toogling of class and the animate example is in the jquery animate docs 我做了一个例子 ,使用类的toogling和动画的例子是在jQuery动画文档

Try using the $('.postimage img') selector. 尝试使用$('.postimage img')选择器。 This should apply any desired effects you set to the img tag wrapped in the postimage div. 这应该将您设置的任何所需效果应用于包装在后postimage div中的img标签。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM