0

i have a problem with this code and i cant't find the problem. It works with JQuery 1.5.2 and lower, but not with JQuery 1.6 and higher.

Here is the code and thanks for your help!

$(document).ready(function () {

    $(".selected").stop().animate({'backgroundPosition':'(0 -28)'}, {duration:200});

    $('#ver li a').hover(

        function ()
        {
            if (!($(this).hasClass("selected")))
            {
            height = $(this).height() * (1);
            $(this).stop().animate({'backgroundPosition':'(0 ' + -height + ')'}, {duration:200});   
            }
        }, 

        function () 
        {
            if (!($(this).hasClass("selected")))
            {
                $(this).stop().animate({'backgroundPosition':'(0 0)'}, {duration:200});
            }   
        }
    );

});
Martin
  • 109
  • 1
  • 9
  • Try with firebug and check the error you're getting. – coder Nov 23 '11 at 15:39
  • What kind of JS error are you getting in the console? – Seth Nov 23 '11 at 15:41
  • Is no error, it works in 1.5.2, the problem is some change in the code from a version to another version, but i can't find that change. – Martin Nov 23 '11 at 15:43
  • Possible duplicate of: http://stackoverflow.com/questions/6322347/jquery-1-6-backgroundposition-vs-backgroundpositionx-and-ff4-compatibility – Niels Nov 23 '11 at 15:44
  • using firebug try to debug your JS – Kishore Nov 23 '11 at 15:45
  • If the version changes it makes us simplest way to do and dosen't change the existing features and every version is compatible with each other. – coder Nov 23 '11 at 15:48
  • No, there are a lot of diferences between JQuery versions. 1.6 brought a lot of changes. The problem is that i can't find the problem. It works in 1.5.2 and lower, but not with 1.6 or higher. – Martin Nov 23 '11 at 16:00
  • As far as I know, `background-position` is not a supported property for jQuery's `animate` function. If you are using a plugin, the problem probably lies between jQuery and the plugin. – Travis Nov 23 '11 at 17:37

2 Answers2

1

I ran into a similar problem, but in my case I was animating just the X axis of the background using something like "backgroundPosition: '+=1350px 0px'", for some reason this stopped working once I went to jQuery 1.6.2... All my other animate instances were working fine, on the same block.

In the end (after a long debug session), I noticed that if I removed the Y-Axis value from the call, it worked. so "backgroundPosition: '+=1350px 0px'" doesnt work anymore, but "backgroundPosition: '+=1350px'" works. The odd thing is that it doesnt even throw an error at you, the animate does process, but nothing happens (so, no error). As of now, I cant figure a way to animate a background image on the Y axis.

Marvin Pinto
  • 30,138
  • 7
  • 37
  • 54
0

Martin, I recommend you download and utilize a DIFF tool, such as WinMerge (http://winmerge.org/) to see the differences between the two versions of jQuery itself.

Analyze the changes, looking specifically for changes in functions that you are using in your code. For example .animate(), .hasClass(), .height(), etc.

I believe you will find the answer after that.

Alternatively, you could analyze the changelogs for each of the versions of jQuery. from 1.5.2 up to 1.6.

Joshua
  • 3,615
  • 1
  • 26
  • 32
  • Thanks for your answer but that tool only works if you have another code to compare. I have only this code and I analyzed the changelogs but I can't find my problem, that's why i'm asking for help. – Martin Nov 23 '11 at 16:32
  • 1
    You can download jQuery Source for 1.5.2 and jQuery Source 1.6 and compare those. All past versions are available here: http://docs.jquery.com/Downloading_jQuery (scroll down the page) – Joshua Nov 23 '11 at 16:34