0
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;
}

对不起,我会一点英语。无论如何我要开始了:D

我想用队列来做这个功能。但我总是 0。我知道我正在这样做。那我该怎么办:D

我可以采用css的变量吗?(div#rozet).top 的变量,我可以在 if 上使用它

4

2 回答 2

0

我在哪里被声明和设置?

但是,你有你的 if (i == 0)

在 $(document).ready(function(){ 之前

这是一个问题。$(document).ready() 是一个事件处理程序,因此 $(document).ready() 中的代码被调用,尽管 i 等于。

您必须重新编写代码,以便

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

}
于 2009-04-15T19:14:39.660 回答
0

您需要使用 else if。如果您正在调用运行这两个 if 的函数,如果 i == 0 则两者都将运行。您可以通过在每个函数中放置警报来检查它。当 i 为 0 时,第一个 if 语句为真并完成工作,并将 i 设置为 1,然后第二个 if 运行它现在也为真,因为最后一个 if 将 i 设置为 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;
  }
});

这是我使用 Firebug 创建的最终结果。如果你有Firebug,你可以在这个页面的控制台中运行它。运行后,您可以单击包含答案数量和排序选项的行。我想这大致就是你要找的。

于 2009-04-15T19:36:41.587 回答