Javascript jquery,用于向下移动图像的鼠标指针

Javascript jquery,用于向下移动图像的鼠标指针,javascript,jquery,image,move,Javascript,Jquery,Image,Move,我是JS新手,我正在努力提高我的JS技能,到目前为止一切都很顺利,到目前为止,我必须在导航中移动img,鼠标进入时向下移动,离开时向上移动。 我尝试过不同的方法来完成它,但我现在卡住了。 现在,当我移过img时,它一直在下降,当我离开时,它就不会回到原位 $(文档).ready(函数(){ $('.foto').mouseenter(函数(){ 动画({marginTop:'+=50'},200); }); $('.foto').mouseleave(函数(){ 动画({marginBotto

我是JS新手,我正在努力提高我的JS技能,到目前为止一切都很顺利,到目前为止,我必须在导航中移动img,鼠标进入时向下移动,离开时向上移动。

我尝试过不同的方法来完成它,但我现在卡住了。 现在,当我移过img时,它一直在下降,当我离开时,它就不会回到原位

$(文档).ready(函数(){
$('.foto').mouseenter(函数(){
动画({marginTop:'+=50'},200);
});
$('.foto').mouseleave(函数(){
动画({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
    });
});

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

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

@凯文:很高兴见到你help@Kevin:很乐意帮忙