2013-01-16 43 views
-1

我有一個jquery,如果不挺的工作應該的方式發言,我覺得已經很接近了,但似乎並不十分想要的工作:jQuery的if語句格式

我就喜歡如下: 如果它是一個ios設備我希望它做一件事,如果它是一個高度大於500像素但小於830的窗口,那麼做另一件事,如果它不是那些事情做第三件事

var deviceAgent = navigator.userAgent.toLowerCase(); 
var agentID = deviceAgent.match(/(iphone|ipod|ipad)/); 


if(agentID) { 
    $("#about_container").css({ 
     height: $(window).height() + 500 
    }); 
    $("#about_main_header_container").css({ 
     paddingBottom: (($(window).height() - $("#about_content_total").outerHeight(true)) /2) - 50 
    }); 
    $("#services_wrapper").css({ 
     height: $(window).height() + 190 
    }); 
    $("#services_main_header_container").css({ 
     paddingBottom: (($(window).height() - $("#services_container").outerHeight(true)) /2) - 10 
    }); 
} 
else if ($(window).height() > 500, $(window).height() < 830) { 
$("#about_container").css({ 
    height: 830 
});  
$("#services_wrapper").css({ 
    height: 830 
}); 
$("#services_main_header_container").css({ 
    paddingBottom: 160 
}); 
$("#about_main_header_container").css({ 
    paddingBottom: 130 
}); 
} 
else { 
    $("#about_container").css({ 
     height: $(window).height() - 65 
    }); 
    $("#about_main_header_container").css({ 
     paddingBottom: (($(window).height() - $("#about_content_total").outerHeight(true)) /2) - 175 
    }); 
    $("#services_wrapper").css({ 
     height: $(window).height() - 100 
    }); 
    $("#services_main_header_container").css({ 
     paddingBottom: (($(window).height() - $("#services_container").outerHeight(true)) /2) - 175 
    }); 
} 
+0

...你想如何工作? – Codeman

+0

你的問題是什麼?你能否給我們更多關於「不太有效」的細節? –

+0

如果它是一個ios設備我希望它做一件事,如果它是一個高度大於500像素但小於830的窗口,那麼做另一件事,如果它們都不是這些東西做第三件事 – loriensleafs

回答

1
else if ($(window).height() > 500, $(window).height() < 830) 

是不對的,應該是:

else if ($(window).height() > 500 && $(window).height() < 830) 

在javascript中,a,b只會返回b

+0

嗯,但他們'不是一回事嗎? – loriensleafs