jQuery 循环插件 &悬停功能有冲突吗?
我的主页上有一个使用 jQuery Cycle 插件 的幻灯片。其标记非常简单,我使用 #slide ul
作为幻灯片放映容器,使用 #slide ul li
作为每张幻灯片。在每个幻灯片项目中,它都会在帖子缩略图的顶部显示标题。
当您将鼠标悬停在缩略图上时,内容摘录会淡入;当您将鼠标悬停在图像上时,内容摘录会淡出。我面临的问题是,当我将鼠标悬停在其中一个缩略图上时,所有内容摘录都会淡入(当然,您看不到其他内容,但我知道它们会淡入,因为当幻灯片切换到新幻灯片时,下一张幻灯片的内容摘录已显示)。
我需要知道的是,如何使用 jQuery 仅使特定幻灯片的内容摘录淡入和淡出,而不是全部淡入淡出?
希望有人能回答我的问题,我总是投票并选择最佳答案。
这是我的 jQuery 代码:
$(document).ready(function() {
$('#slide ul').cycle({
fx: 'turnDown',
next: '#slidenext',
prev: '#slideprev',
speed: 600,
delay: 3000
});
$('#slide ul').hover(function() {
$(this).cycle('pause');
$('#slideshow ul .text, #slideshow ul .more').animate({opacity: 'show'});
},function() {
$(this).cycle('resume');
$('#slideshow ul .text, #slideshow ul .more').animate({opacity: 'hide'});
});
$('#slidenext, #slideprev').click(function() {
$('#slideshow ul .text, #slideshow ul .more').animate({opacity: 'hide'});
});
});
对于幻灯片:
<div id="slide">
<ul>
<?php $my_query = new WP_Query('posts_per_page=3');
if ($my_query->have_posts()) : while ($my_query->have_posts()) : $my_query->the_post();
$do_not_duplicate = $post->ID;?>
<li>
<!-- slide content -->
<img src="<?php bloginfo('template_url'); ?>/images/slide-post-thumb.png" width="750" height="220" alt="" />
<h1><a href="<?php the_permalink(); ?>" title="Permanent link to <?php the_title(); ?>"><?php the_title(); ?></a></h1>
<div class="text"><?php the_excerpt(); ?></div>
<div class="more"><a href="<?php the_permalink(); ?>" title="Read the story <?php the_title(); ?>">Read Story</a></div>
</li>
<?php endwhile; else : ?>
<p>Sorry, no posts found!</p>
<?php endif; ?>
</ul>
</div>
I have a slideshow on my homepage using the jQuery Cycle plugin. The markup for that is pretty simple, I used #slide ul
as the slideshow container and #slide ul li
as each slide. Inside each of these slideshow items, it displays the title on top of the posts thumbnail.
When you hover over the thumbnail, the content excerpt fades in and when you hover off of the image, the content excerpt fades out. The problem I'm facing is that when I hover over one of the thumbnails, ALL of the content excerpts fade in (granted, you can't see the other ones, but I know they do because when the slideshow switches to a new slide, the content excerpt for the next slide is already showing).
What I need to know is how can I make only the content excerpt for that specific slide fade in and out instead of all of them using jQuery?
Hope someone can answer my question, I always vote up and pick a best answer.
Here's my jQuery code:
$(document).ready(function() {
$('#slide ul').cycle({
fx: 'turnDown',
next: '#slidenext',
prev: '#slideprev',
speed: 600,
delay: 3000
});
$('#slide ul').hover(function() {
$(this).cycle('pause');
$('#slideshow ul .text, #slideshow ul .more').animate({opacity: 'show'});
},function() {
$(this).cycle('resume');
$('#slideshow ul .text, #slideshow ul .more').animate({opacity: 'hide'});
});
$('#slidenext, #slideprev').click(function() {
$('#slideshow ul .text, #slideshow ul .more').animate({opacity: 'hide'});
});
});
And for the slideshow:
<div id="slide">
<ul>
<?php $my_query = new WP_Query('posts_per_page=3');
if ($my_query->have_posts()) : while ($my_query->have_posts()) : $my_query->the_post();
$do_not_duplicate = $post->ID;?>
<li>
<!-- slide content -->
<img src="<?php bloginfo('template_url'); ?>/images/slide-post-thumb.png" width="750" height="220" alt="" />
<h1><a href="<?php the_permalink(); ?>" title="Permanent link to <?php the_title(); ?>"><?php the_title(); ?></a></h1>
<div class="text"><?php the_excerpt(); ?></div>
<div class="more"><a href="<?php the_permalink(); ?>" title="Read the story <?php the_title(); ?>">Read Story</a></div>
</li>
<?php endwhile; else : ?>
<p>Sorry, no posts found!</p>
<?php endif; ?>
</ul>
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你的问题是你的选择器太笼统了。请尝试这样做:
基本想法是您只想为当前幻灯片的摘录和链接设置动画。您可以通过将悬停添加到
元素,然后从那里搜索
.text
和.more
来实现这一点,或者,与在.click
处理程序中一样,通过在li.activeSlide
下查找.text
和.more
来实现。我假设您使用的是 默认activePagerClass
选项,如果您使用其他东西,请适当更改activeSlide
。I think your problem is that your selectors are too general. Try this instead:
The basic idea is that you only want to animate the excerpt and link for the current slide. You can get that by adding the hover to the
<li>
elements and then searching from there for the.text
and.more
or, as in the.click
handler, by looking for.text
and.more
underli.activeSlide
. I'm assuming that you're using the defaultactivePagerClass
option, if you're using something else then changeactiveSlide
appropriately.