왜이 용도로 자바 스크립트를 사용하고 있습니까? 순수 CSS로 수행 할 수 있습니다 앤디 제안처럼
@media screen and (max-width: 980px), projection and (max-width: 980px)
{
/* first undo the general styles */
#gradient #wrapper #camboxs .cambox:nth-child(5n):not(#gradient #wrapper #footer .box #camboxs .combox)
{
margin-right: 10px; /* replace with the original margin */
}
#gradient #wrapper #camboxs .cambox:nth-child(2n):not(#gradient #wrapper #footer .box #camboxs .combox)
{
margin-right: 0;
}
}
,이 방법은 적은 코드와 함께 할 수있다 :
#gradient #wrapper #camboxs .cambox:nth-child(5n):not(#gradient #wrapper #footer .box #camboxs .combox)
{
margin-right: 0;
}
그리고는 미디어 쿼리를 사용합니다.
그리고 대체에 대한
는 다음 (안된) jQuery를 함께 다음과 같은 사용, 창 크기 조절에 반응 :
$(window).resize(function() {
if ($(window).width() <= 980) {
$("#gradient #wrapper #camboxs .cambox:nth-child(5n)").not("#gradient #wrapper #footer .box #camboxs .combox").css("margin-right","");
$("#gradient #wrapper #camboxs .cambox:nth-child(2n)").not("#gradient #wrapper #footer .box #camboxs .combox").css("margin-right","0");
} else {
$("#gradient #wrapper #camboxs .cambox:nth-child(2n)").not("#gradient #wrapper #footer .box #camboxs .combox").css("margin-right","");
$("#gradient #wrapper #camboxs .cambox:nth-child(5n)").not("#gradient #wrapper #footer .box #camboxs .combox").css("margin-right","0");
}
});
예제 코드 : http://twitter.github.com/bootstrap/assets/css/bootstrap-responsive.css – JasonWoof
선택자는 실제로 복잡하고 지나치게 장황합니다. 왜 그냥 $ ('camboxs .cambox : nth-child (5n)')를 사용하지 않는 것이 좋을까요? ID는 고유하므로 더 빨리 만드는 것 외에 다른 점이 없습니다. – Andy