2012-06-14 97 views
2
$("#button").click(function(){ 
    if($("#window").css('top') == '0%'){ 
     $("#window").stop().animate({top:'-100%'},1000); 
    } 
    else { 
     $("#window").stop().animate({top:'0%'},1000); 
    } 
}); 

它可以在Chrome和Safari中完美工作,但在Firefox中它可以部分工作。jquery if else not in FF

在FF中,它仅适用于else的情况。标识该位置不是top: '0%'并更改为top: '0%',但不更改为top: '-100%'如果是top: '0%'

请建议。

+0

什么时候你调试/日志值吗? –

回答

1

删除百分比符号和使用top: 0;

+0

Firefox在'top'和其他'位置'函数上返回'px',而不是百分数,我为akin写了一些函数http://stackoverflow.com/questions/9320593/jquery-cssleft-reports-px-instead-of/9321104#9321104 – deerua

+0

老兄,谢谢你的观察。但我需要用百分比来解决它,因为'#window'div是'height:100%',所以要盲目使用'top:-100%'。你是完全正确的,但我想问题是'-100%',因为在我所有的尝试中,div移动到'0%'但从未移动到'-100%' – LGVentura

+0

,但是这只发生在使用if和其他情况。当我仅用于示例时,它完美地工作:$(“#menuinformacoes”)。toggle(function(){ \t $(“#informacoes”)。animate({top:'0%'},1300); ({#informacoes“)。animate({top:' - 100%'},1300); }); – LGVentura