Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用jQuery设置悬停时背景位置的动画_Jquery_Html_Css - Fatal编程技术网

使用jQuery设置悬停时背景位置的动画

使用jQuery设置悬停时背景位置的动画,jquery,html,css,Jquery,Html,Css,所以我有一个div,我通过CSS添加了一个背景图像。我希望使用jQuery将图像设置为悬停时的不同位置 我的一切工作,除了动画没有发射。为了简化代码,我创建了一个场景示例 以下是HTML: <div class="moveMe"></div> 问题是jQuery: $('.moveMe') .css( {backgroundPosition: "0% 0%"} ) .hover( function() { $(t

所以我有一个div,我通过CSS添加了一个背景图像。我希望使用jQuery将图像设置为悬停时的不同位置

我的一切工作,除了动画没有发射。为了简化代码,我创建了一个场景示例

以下是HTML:

<div class="moveMe"></div>
问题是jQuery:

 $('.moveMe')
    .css( {backgroundPosition: "0% 0%"} )
    .hover(
        function() {
            $(this).stop().animate({backgroundPosition: "100% 0%"}, "600");
        },
        function() {
            $(this).stop().animate({backgroundPosition: "0% 0%"}, "600");
        });
让你知道:

  • jQuery已加载
  • jQuery代码在文档加载函数中
我尝试更改动画属性来更改悬停时的宽度,结果成功了,所以我认为我的问题在于
backgroundPosition
语法或其他方面

这让我发疯了,任何帮助都会很好。

检查以下内容:


我刚切换到
background-position-x

谢谢你的工作就像一个魔咒!但有一件事,你能解释一下为什么“背景位置”不起作用吗?非常感谢。
 $('.moveMe')
    .css( {backgroundPosition: "0% 0%"} )
    .hover(
        function() {
            $(this).stop().animate({backgroundPosition: "100% 0%"}, "600");
        },
        function() {
            $(this).stop().animate({backgroundPosition: "0% 0%"}, "600");
        });