javascript - jquery, mouseenter 下移图片

标签 javascript jquery image move

我是JS新手,我正在努力提高我的JS技能,到目前为止一切都很顺利,到目前为止,我必须在nav中 move img,当鼠标进入时它会向下 move ,当它离开时会向上 move 。 https://www.youtube.com/embed/8qKRf0cg3Co

我尝试了不同的方法来完成它,但我现在陷入困境。 现在,当我 move img 时,它会不断下降,当我离开时,它不会回到原位。

$(文档).ready(函数(){ $('.foto').mouseenter(function () { $(this).animate({marginTop: '+=50'}, 200); }); $('.foto').mouseleave(函数(){ $(this).animate({marginBottom: '-=50'}, 200); });

最佳答案

您需要在 mouseleave 中使用 marginTop 而不是 marginBottom

$(document).ready(function (){
    $('.foto').mouseenter(function () {
        $(this).animate({marginTop: '+=50'}, 200);
    });
    $('.foto').mouseleave(function (){
        $(this).animate({marginTop: '-=50'}, 200);
        //               --^-- change here
    });
});

关于javascript - jquery, mouseenter 下移图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32719291/

相关文章:

javascript - 有没有办法为主页预加载完整的背景封面图片

javascript - 具有多种输入类型的自动完成功能,动态插入

javascript - 有没有办法从片段重建有效的 HTML 结构?

javascript - 有没有更优雅的方法来编写一个函数,根据函数的参数返回图像的名称?

javascript - for循环中的jQuery setinterval

java - 如何在 Tomcat 服务器上保存和加载图像

javascript - 当实际结束时播放列表中的下一个 YouTube 视频

jquery - Magento:添加外部 jQuery 文件

javascript - 检测鼠标方向

android - 下一个/上一个按钮幻灯片图像