jQuery Mouseenter/Mouse离开图像交换 [英] Jquery Mouseenter/Mouse Leave image swap

查看:139
本文介绍了jQuery Mouseenter/Mouse离开图像交换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我写了这段代码来尝试一些新的方式来进行图像交换以进行预加载,这给我带来了麻烦.

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!

这是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();
        });
});

推荐答案

我认为您正在寻找

mouseenter和mouseleave都只接受一个参数,但是您要定义两个回调函数.

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

这篇关于jQuery Mouseenter/Mouse离开图像交换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆