0
var d= $('#menu-top-menu').children();
d.hover(function(){
    var e= $(this).position().left;
    var f= $(this).parent().position().left;
    var g= e-f;
    $('#menu-top-menu').animate({backgroundPosition, g + "px 3px"});
    console.log(g);
});

I dont know why it is not animating. could you give me some clue to solve the problem? Thanks

architesa
  • 79
  • 2
  • 7

2 Answers2

2

You need to supply the properties to animate separately, and also the correct syntax is to separate the key/value of an objects parameters by a : not a comma. Try this:

var d= $('#menu-top-menu').children();
d.hover(function(){
    var e= $(this).position().left;
    var f= $(this).parent().position().left;
    var g= e-f;
    $('#menu-top-menu').animate({
        'background-position-x': g + 'px', 
        'background-position-y': '3px'
    });
    console.log(g);
});

You could also leave out background-position-y assuming it never changes, and is set in CSS.

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
0

Check with this ... hope it will work( for help : http://api.jquery.com/animate/):

$("#menu-top-menu").animate({
    background-position-x:"20px", 
    background-position-y: "3px"
  },1500);
Anup
  • 3,283
  • 1
  • 28
  • 37