나는 그것을 알아 냈다. 코드 here을 볼 수 있습니다.
function px_to_em(px_value, container) {
////////////////////////////////
// Detect Contianer Font Size //
////////////////////////////////
//Prepend a span tag to the container for testing
$(container).prepend("<span id='wraping_span_to_test'></span>");
//Set the span to height 1em and then save the pixel height to the container_ft_sz variable
container_ft_size = $("#wraping_span_to_test").css({
"font-family": "inherit",
"font-size": "inherit",
"font-style": "inherit",
"font-variant": "inherit",
"font-weight": "inherit",
"line-height": "inherit",
"margin": "0 !important",
"padding": "0 !important",
"border": "0 !important",
"outline": "0 !important",
"background-color": "aqua",
"height": "1em",
"width": " 1em",
"display": "block"
}).height();
//Remove the testing span
$("#wraping_span_to_test").remove();
//Use values to convert to ems
var round_to = 1000;
return Math.round((px_value/container_ft_size) * round_to)/round_to;
}
이것은 당신이 & 간단한 함수를 호출하여 그들을 측정으로 변환 픽셀로 측정 jQuery로 측정을 찾을 수 있도록해야합니다.
정말 답할 코드가 필요합니다. CSS 클래스를 사용하는 것은 작업을 수행하고 jQuery는 코드를 보지 않고 HTML에 클래스를 추가한다고 생각합니다. 이것이 진행 방법인지 여부는 알 수 없습니다. –
표시 할 코드가 너무 많습니다. & 그게 작동하지 않을 것입니다. 나는 동적으로 요소와 스타일을 만들고 있습니다. 저는 무언가의 너비와 같은 측정 값을 감지하고 var로 설정하고 다른 요소의 위치를 설정합니다. 예를 들어 var. 명확히하는 데 도움이되기를 바랍니다. –
클래스를 동적으로 만들어야하는 이유가 있습니까? css 파일에 포함시킬 수 없으며 jQuery에서 dom 요소의 클래스 만 변경할 수 있습니까? –