滚动JQuery-移动

滚动JQuery-移动,jquery,Jquery,我有一个带img的简单按钮。双img:顶部蓝色箭头,底部绿色箭头(高44px)。由于不同的原因,我不能将img置于背景中。因此,我尝试将img放入html中,并使用jQuery移动它。但它不动。有人能帮忙吗? HTML: JAVASCRIPT: $(function(){ $("#button").hover(function() { $("#button #arrow").animate({top: "-22"}, 1200); }); }) ​ 下面是

我有一个带img的简单按钮。双img:顶部蓝色箭头,底部绿色箭头(高44px)。由于不同的原因,我不能将img置于背景中。因此,我尝试将img放入html中,并使用jQuery移动它。但它不动。有人能帮忙吗?

HTML:

JAVASCRIPT:

$(function(){

    $("#button").hover(function() {
        $("#button #arrow").animate({top: "-22"}, 1200);
    });

})

下面是使用jQuery对滚动图像的代码库的简单解决方案

$(function() {
    $("#button #arrow").mouseenter(function() {
        $("#button #arrow").animate({
            top: "-17"
        }, 500);
    });
    $("#button #arrow").mouseleave(function() {
        $("#button #arrow").animate({
            top: "0"
        }, 500);

    });
});

尝试演示:

您是否正在尝试执行此操作:

jQuery

$(function(){

    $("#button").hover(function() {
        $("#button #arrow").animate({top: "-17px"}, 1200);
    }, function(){
        $("#button #arrow").animate({top: "0px"}, 1200);
    });

})

你想这么做吗:是的!完美的现在,我使用svg添加了一些更复杂的内容。你知道为什么boto png工作而buto svg不工作吗?这只是一份拷贝。我已经花了好几个小时,但它不起作用:我已经把它作为一个答案发布了,所以如果你觉得它是一个答案,那么你可以接受它作为一个答案。此外,(SVG)是一系列用于二维向量图形的基于XML的文件格式规范,而(PNG)是一种采用无损数据压缩的位图图像格式。要制作SVG文件的动画,必须阅读这篇文章:两个答案都是正确的,而且都很好。谢谢阿桑和凯尔!这两个答案都是正确的,效果很好。谢谢阿桑和凯尔!
$(function() {
    $("#button #arrow").mouseenter(function() {
        $("#button #arrow").animate({
            top: "-17"
        }, 500);
    });
    $("#button #arrow").mouseleave(function() {
        $("#button #arrow").animate({
            top: "0"
        }, 500);

    });
});
$(function(){

    $("#button").hover(function() {
        $("#button #arrow").animate({top: "-17px"}, 1200);
    }, function(){
        $("#button #arrow").animate({top: "0px"}, 1200);
    });

})