使用php作为选择器的jquery
嗨,我正试图在悬停时显示一个隐藏的div来覆盖我的图像,我有一个列表,它是从wordpress中的项目帖子中动态生成的。显然,列表类名都是不同的 我的选择器应该是什么,以便div正好出现在悬停的列表项上使用php作为选择器的jquery,jquery,wordpress,Jquery,Wordpress,嗨,我正试图在悬停时显示一个隐藏的div来覆盖我的图像,我有一个列表,它是从wordpress中的项目帖子中动态生成的。显然,列表类名都是不同的 我的选择器应该是什么,以便div正好出现在悬停的列表项上 <li class="item-<?php the_ID() ?> <?php if(++$count%4==0) echo 'rightmost'?> "> <div class="image">
<li class="item-<?php the_ID() ?> <?php if(++$count%4==0) echo 'rightmost'?> ">
<div class="image">
<span>
<a href="<?php the_permalink() ?>">
<?php
if(has_post_thumbnail()){
the_post_thumbnail('post-thumb');
}
?>
</a>
</span>
<a href="<?php the_permalink() ?>" class="link">View Details</a>
</div>
<div class="content">
<h2><a href="<?php the_permalink() ?>"><?php the_title() ?></a></h2>
<span class="tags">
<?php
// Fetching the tag names with respect to the post and displaying them
$args = array('orderby' => 'name', 'order' => 'ASC', 'fields' => 'names');
echo implode(wp_get_object_terms( $post->ID, 'tag', $args),', ');
?>
</span>
<p>
<?php
// Using custom excerpt function to fetch the excerpt
folio_excerpt('folio_excerpt_length','folio_excerpt_more');
?>
</p>
</div>
<div class="clear"></div>
</li>
<?php endwhile; ?>
</ul>
<script>
$(document).ready(function() {
$('.item-<?php the_ID() ?>').hover(
function(){
$('#folio li .content').fadeIn();
},
function() {
$("#folio li .content").fadeOut();
});
});
</script>
通过查看您的代码,我发现有一个容器具有id对开本
我们使用:
jQuery("#folio ul li").hover(function(){
jQuery(this).children("span").fadeOut();
});
这解决了您的问题吗?您可以将您的id存储在数据属性中,然后有一个类可用于jQuery选择器,如:
HTML:
jQuery提供了多种方法来遍历DOM,因此可以使用多种解决方案来实现这一点,以下是一种:
$(document).ready(function() {
$('#folio li').hover(function(){
$(this).find('.content').fadeIn();
},function() {
$(this).find('.content').fadeOut();
});
});
重要提示:第二行是示例。我不知道当用户将鼠标悬停在li上时,您到底想做什么。现在查看该网站,它已更新,您可以看到我的问题。您尝试过哪些jquery代码?为什么你不能只使用.image
?我将我的行设置为@Blake post完整的标记(使用.content
)以及你的问题中的jquery代码,这样我们就可以准确地了解你想要做的事情,如果你上面评论的是你的实际代码,那么使用函数(){function()就有问题了
如果上述操作无效,请检查浏览器控制台(Ctrl+Shift+J)并修复您遇到的任何错误!但请访问网站,在您悬停时查看我的问题it@Blake是的,我实际上只是在想你会遇到这个问题,检查我上面的更新,使用列表项而不是.image
来触发事件。是的,我已经测试过了,但似乎没有工作更正你就是那个人!没看见。发现…非常感谢你!
$(".hover").hover(function() {
// Do something with id, show div, etc.
});
$(document).ready(function() {
$('#folio li').hover(function(){
$(this).find('.content').fadeIn();
},function() {
$(this).find('.content').fadeOut();
});
});