Jquery Mouseenter/Mouse Leave 图像交换

发布于 2024-08-04 09:20:08 字数 1008 浏览 5 评论 0原文

因此,我编写了这一小段代码来尝试一些新的方法来进行图像交换以实现预加载,但我遇到了一些麻烦。

我的问题是,我有一个包含图像的容器,其中有一些填充和文本,但只有当有人滚动图像而不是容器时,才会激活翻转。我一定有一些小错误,希望有人能帮助我。还在学习!

这是 html:

<div class="projectThumb">
    <img src="/img/aeffect_button_static.gif" width="146" height="199" class="static" name="aeffect" alt="" />        
    <img src="/img/aeffect_button_rollover.jpg" width="146" height="199" class="rollover" name="aeffect" alt="" />
    <p class="title">A.EFFECT: Film Poster</p>
</div>

这是 jquery:

$(document).ready(function(){
    $(".rollover").hide();
$(".projectThumb").mouseenter(
        function(){
            $(this).attr(".static").hide();
        }, 
        function(){
            $(this).attr(".rollover").show();
        });
$(".projectThumb").mouseleave(
        function(){
            $(this).attr(".rollover").hide();
        },
        function(){
            $(this).attr(".static").show();
        });
});

So I wrote this little bit of code to try out some new way of doing an image swap for purposes of preloading and I am having a bit of trouble.

My problem is that I have a container with the images that has some padding and text, but the activation of my rollover only happens when someone rolls over the image, instead of the container. I must have some small bit wrong, hopefully someone can help me out. Still learning!

Here is the html:

<div class="projectThumb">
    <img src="/img/aeffect_button_static.gif" width="146" height="199" class="static" name="aeffect" alt="" />        
    <img src="/img/aeffect_button_rollover.jpg" width="146" height="199" class="rollover" name="aeffect" alt="" />
    <p class="title">A.EFFECT: Film Poster</p>
</div>

Here is the jquery:

$(document).ready(function(){
    $(".rollover").hide();
$(".projectThumb").mouseenter(
        function(){
            $(this).attr(".static").hide();
        }, 
        function(){
            $(this).attr(".rollover").show();
        });
$(".projectThumb").mouseleave(
        function(){
            $(this).attr(".rollover").hide();
        },
        function(){
            $(this).attr(".static").show();
        });
});

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

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

发布评论

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

评论(2

↙厌世 2024-08-11 09:20:08

我认为您正在寻找 hover

$(document).ready(function(){
    $(".rollover").hide();
    $(".projectThumb").hover(
    function(){
        $(this).find(".static,.rollover").toggle();
    }, 
    function(){
        $(this).find(".static,.rollover").toggle();
    });
});

mouseenter 和 mouseleave 都只接受一个参数,但您正在定义两个回调函数。

I think you're looking for hover:

$(document).ready(function(){
    $(".rollover").hide();
    $(".projectThumb").hover(
    function(){
        $(this).find(".static,.rollover").toggle();
    }, 
    function(){
        $(this).find(".static,.rollover").toggle();
    });
});

Both mouseenter and mouseleave only take one argument, but you're defining two callback functions.

涫野音 2024-08-11 09:20:08

为什么不尝试:

$(".projectThumb").bind("mouseenter mouseleave", function(e) {
    $(this).toggle();
});

Why not try:

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