views:

596

answers:

2
if(i==0){
      $(document).ready(function(){
     $("div#rozet").hover(function(){
       $(this).hide("fast");
       $(this).animate(
                   { top:'+45px', left:'+500px'},
          {duration: 1}
          );  
      $(this).show("slow");           
      $(this).stopall();
        });
i=1;
}
if(i==1){
     $("div#rozet").hover(function(){
       $(this).hide("fast");
       $(this).animate(
                   { top:'-85px', left:'+500px'},
          {duration: 1}
          );  
      $(this).show("slow");           
      $(this).stopall();
        });
    });
i=0;
}

I'm sorry, I have a little English. Anyway I'm starting :D

I want to do this functions with queue. But i is always 0. I know I'm doing this. So what can I do :D

Can I take css's variables. (div#rozet).top's variable, I can use it on if

A: 

where is i being declared and set?

BUT, you have your if (i == 0)

before the $(document).ready(function(){

That is a problem. $(document).ready() is an event handler, so the code in $(document).ready() is being called, in spite of what i is equal to.

You have to rework your code so that

$(document).ready(function(){
  if (i == 0) {
    ...
  }
  if (i == 1) {
    ...
  }

}
Chris Brandsma
A: 

You need to use an else if. If you are calling a function that runs those two ifs, both will run if i == 0. You can check it by putting an alert in each function. When i is 0, the first if statement is true and does the work, and sets i to 1 and than the second if runs it now also is true since the last if set i to 1.

i = 0;
jQuery("#subheader").click(function () {
  if (i == 0) {
    alert ("i was 0");
    i = 1;
  }
  else if (i == 1) {
    alert ("i was 1");
    i = 0;
  }
});

This is the end result I created using Firebug. If you have Firebug you can run this in the console on this page. Once it is run, you can click on the line that contains the number of answers and the sorting options. I think that is roughly what you were looking for.

Philip T.