Jquery Mouseenter/Mouse Leave 图像交换
因此,我编写了这一小段代码来尝试一些新的方法来进行图像交换以实现预加载,但我遇到了一些麻烦。
我的问题是,我有一个包含图像的容器,其中有一些填充和文本,但只有当有人滚动图像而不是容器时,才会激活翻转。我一定有一些小错误,希望有人能帮助我。还在学习!
这是 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为您正在寻找 hover:
mouseenter 和 mouseleave 都只接受一个参数,但您正在定义两个回调函数。
I think you're looking for hover:
Both mouseenter and mouseleave only take one argument, but you're defining two callback functions.
为什么不尝试:
Why not try: