2013-09-04 7 views
0

페이지 초기화 또는 페이지 크기 조정시 높이 계산에 차이가있는 것으로 보입니다.Jquery .ready와 .resize 사이의 높이 차이 계산

실마리가있는 사람은 누구입니까? 또는 그것을 고치는 방법?

예제 코드

$(document).ready(function() { 

    showcase_height_init(); 

    $(window).resize(function() { 
     showcase_height_init(); 
    }); 

}); 

function showcase_height_init() { 

    var showcase_container_text_height = ($("#showcase_container_text").height())/2; 

    $("#showcase_container_text").css({ 
     margin: '-'+showcase_container_text_height+'px 0 0' 
    }); 

} 

답변

0

DOM에 따라서 사용할 수 있습니다 스타일, 이미지 및 기타 리소스를로드 요소 돈의 높이되지 않는 한 속성이 가능하다 같이 "준비"이벤트는 즉시 실행됩니다 진짜가 아니야.

이러한 목적을 위해 당신은 시도해야합니다 :

http://api.jquery.com/ready/

:
$("body").load(function() { 

    showcase_height_init(); 

    $(window).resize(function() { 
     showcase_height_init(); 
    }); 

}); 

function showcase_height_init() { 

    var showcase_container_text_height = ($("#showcase_container_text").height())/2; 

    $("#showcase_container_text").css({ 
     margin: '-'+showcase_container_text_height+'px 0 0' 
    }); 

} 

내가 jQuery의 문서를 추천합니다