jQuery 语法问题,我认为很简单

发布于 2024-09-04 23:43:59 字数 491 浏览 4 评论 0原文

$(document).ready(function() { $(".module .caption").hide(); $(".module").hover(function() { $(this).find(".caption").slideDown(); },function() { $(this).find(".caption").slideUp(); }); });

这个片段非常适合我的目的,唯一需要注意的是我需要 .module 悬停功能来同时向所有其他不是 $this 的“.caption”添加一类“under”,然后在悬停结束。所以基本上我不希望悬停的“模块”来获取类,我希望它完全按照我在这里显示的方式进行...在结束悬停时上下滑动 .caption,我只想要所有其他“.caption”。当任何“.module”悬停时,标题“s 获取下类。

我一直在尝试的事情陷入了死胡同,想用同样的功能来做。有什么想法吗?

$(document).ready(function() {
$(".module .caption").hide();
$(".module").hover(function() {
$(this).find(".caption").slideDown();
},function() {
$(this).find(".caption").slideUp();
});
});

This snippet works great for my purposes, the only caveat is that I need the .module hover function to simultaneously add a class of "under" to all other ".caption"'s that are not $this, and then remove them when the hover ends. So basically I don't want the "module" that is hovered to get the class, I want it to do exactly what I am showing here...sliding .caption up and down on end hover, I just want all other ".caption"s to get the under class when any ".module" is hovered.

Just hitting a dead end with what I have been trying, want to do it in the same function. Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

迟月 2024-09-11 23:43:59

根据你的 html 结构,类似这样的事情可能会做到这一点:

<script type="text/javascript">
 $(document).ready(function() {
  $(".module .caption").hide();
  $(".module").hover(function() {
    $(this)
      .find(".caption").slideDown().end()
      .siblings('.module').children('.caption').addClass('under');

   },function() {
    var $this = $(this);

    $this.find(".caption").slideUp();

    setTimeout(function() { 
      $this
        .siblings('.module').children('.caption').removeClass('under');   
   }, 1000);
 });
</script>

Depending on your html structure something like this might do it:

<script type="text/javascript">
 $(document).ready(function() {
  $(".module .caption").hide();
  $(".module").hover(function() {
    $(this)
      .find(".caption").slideDown().end()
      .siblings('.module').children('.caption').addClass('under');

   },function() {
    var $this = $(this);

    $this.find(".caption").slideUp();

    setTimeout(function() { 
      $this
        .siblings('.module').children('.caption').removeClass('under');   
   }, 1000);
 });
</script>
初见你 2024-09-11 23:43:59

只需将该类添加到所有其他标题中,然后将其从匹配的标题中删除即可。在悬停结束时,只需将其从所有这些中删除即可。

Just add the class to all other captions, and then remove it from the matched caption. At the end of the hover just remove it from all of them.

〃安静 2024-09-11 23:43:59
$(function () {

        $('a').hover(function () {
            $(this).addClass('on');
            $('a:not(.on)').addClass('noton');

        }, function () {
            $(this).removeClass('on');
            $('a:not(.on)').removeClass('noton');

        });
    });
$(function () {

        $('a').hover(function () {
            $(this).addClass('on');
            $('a:not(.on)').addClass('noton');

        }, function () {
            $(this).removeClass('on');
            $('a:not(.on)').removeClass('noton');

        });
    });
早茶月光 2024-09-11 23:43:59

我不确定这是否有帮助,因为我不知道“under”类到底是做什么的。

$(".module").hover(function() {
         $(".caption").addClass("under");
         $(this).find(".caption").removeClass("under").slideDown(); 
       },function() {
         $(this).find(".caption").slideUp();
         $(".caption").removeClass("under");   
       });

I'm not sure if this will help as i don't know what the "under" class does exactly.

$(".module").hover(function() {
         $(".caption").addClass("under");
         $(this).find(".caption").removeClass("under").slideDown(); 
       },function() {
         $(this).find(".caption").slideUp();
         $(".caption").removeClass("under");   
       });
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文