Jquery悬停功能未按预期工作

发布于 2025-01-06 18:57:04 字数 868 浏览 3 评论 0原文

我想让用户能够查看我开发的网站的完整屏幕截图,然后当他们将鼠标悬停在该网站上时,另一个 div 会淡入其中并包含一些元信息。

这是一个测试链接 - http://www.deanelliott.me/misc/test -port/index.html

正如您所看到的,如果您将鼠标悬停在幻灯片上,则会出现一个覆盖层,这很好,但是当您将鼠标悬停在幻灯片上并且下一张幻灯片开始播放时,覆盖层会在不应该可见的情况下可见是。

如果有人对问题是什么有任何想法那就太好了!

谢谢

编辑:这是相关代码

$(function(){
$('#slideshow').hover(
    function(){
            $('.slideimage').fadeOut(100, function(){
                    $('.slideoverlay').fadeIn(100);                                            
            });
    },
    function(){
            $('.slideoverlay').fadeOut(100, function(){
                    $('.slideimage').fadeIn(100);                                           
            });
    }
    );
});

.slideoverlay 通过 CSS 设置为 display:none

I want to be enable users to view a full screenshot of a website I have developed and then when they hover over it another div fades in with some meta information.

Here is a test link - http://www.deanelliott.me/misc/test-port/index.html

As you can see, if you hover over the slideshow an overlay appears which is fine, but when you hover off it and the next slide comes into play the overlay is visible when it shouldn't be.

If anyone has any ideas on what the problem is that would be great!

Thanks

Edit: Here is the relevant code

$(function(){
$('#slideshow').hover(
    function(){
            $('.slideimage').fadeOut(100, function(){
                    $('.slideoverlay').fadeIn(100);                                            
            });
    },
    function(){
            $('.slideoverlay').fadeOut(100, function(){
                    $('.slideimage').fadeIn(100);                                           
            });
    }
    );
});

.slideoverlay is set to display:none via CSS

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

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

发布评论

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

评论(1

疧_╮線 2025-01-13 18:57:04

由于某种原因,您的 fadeIn() 被应用于所有幻灯片叠加,但 fadeOut() 仅应用于当前可见的幻灯片。我会尝试使 fadeIn()fadeOut 仅影响您悬停在其上的实际内容。像这样的事情:

$(function(){
    $('#slideshow .slide').hover(
        function(){
            var $this = $(this);
            $this.find('.slideimage').fadeOut(100, function(){
                $this.find('.slideoverlay').fadeIn(100);                                            
            });
        },
        function(){
            var $this = $(this);
            $this.find('.slideoverlay').fadeOut(100, function(){
                $this.find('.slideimage').fadeIn(100);                                           
            });
        }
    );
});

可能可以使用一些优化,但我认为这应该可行。不过还没有测试过,祝你好运。

尝试用此方法消除白色闪光。基本上,我们的想法是,如果您只是将覆盖层覆盖在 $('.slideimage') 上,则无需隐藏它。您所需要做的就是隐藏和显示幻灯片。

$(function(){
    $('#slideshow .slide').hover(
        function(){
            var $this = $(this);
            $this.find('.slideoverlay').fadeIn(100);                                            
        },
        function(){
            var $this = $(this);
            $this.find('.slideoverlay').fadeOut(100);
        }
    );
});

For some reason your fadeIn() is getting applied to all of the slideoverlays but the fadeOut() only gets applied to the currently visible one. I would try to make it so that the fadeIn() and fadeOut only effect the actual one you are hovering over. Something like this:

$(function(){
    $('#slideshow .slide').hover(
        function(){
            var $this = $(this);
            $this.find('.slideimage').fadeOut(100, function(){
                $this.find('.slideoverlay').fadeIn(100);                                            
            });
        },
        function(){
            var $this = $(this);
            $this.find('.slideoverlay').fadeOut(100, function(){
                $this.find('.slideimage').fadeIn(100);                                           
            });
        }
    );
});

Could probably use some optimization, but I'm thinking this should work. Haven't tested though, so good luck.

Try this to get rid of the white flash. Basically, the thought is you don't need to hide the $('.slideimage') if you're just overlaying the overlay over it. All you need to do is hide and show the slideoverlay.

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