이 함수를 jQuery로 변경하려고 계속 시도했지만 올바르게 실행하지 못했습니다. 아무도 나에게 어떤 도움도 전혀주지 못했습니까?이 함수를 Javascript에서 jQuery로 변환합니다.
window.onresize = resizeImage;
function resizeImage(){
var newHeight = document.documentElement.clientHeight;
var newWidth = document.documentElement.clientWidth;
document.getElementById('crofthouse').width = (newHeight/2) * 1.33;
document.getElementById('crofthouse').height = (newHeight/2);
document.getElementById('main').style.width = (newHeight/2) * 1.33;
document.getElementById('main').style.height = (newHeight/2);
var margin = (newHeight - document.getElementById('crofthouse').height)/2;
document.getElementById('main').style.margin = margin + ',auto,' + margin + ',auto';
}
여기로 변환하려고 시도한이다 window.onresize = resizeImage;
function resizeImage(){
var newHeight = document.documentElement.clientHeight;
var newWidth = document.documentElement.clientWidth;
$("#crofthouse").css("width, (newHeight /2) * 1.33")
$("#crofthouse").css("hegiht, (newHeight /2)")
$("#main").css("width, (newHeight /2) * 1.33")
$("#main").css("height, (newHeight /2)")
var margin = (newHeight - $('#crofthouse').css("height)/2");
$('main').css("margin = margin + ',auto,' + margin + ',auto'");
}
document.getElementById ("sth")는 첫 번째 변경 인 $ ("# sth")로 바꿀 수 있습니다. 제대로 작동하지 않는다는 것은 무엇을 의미합니까? – lc2817
가장 좋은 시도는 무엇입니까 (질문에 게시)? –
CSS는 JavaScript를 "이해하지 못합니다". 'document.getElementById ('crofthouse'). width = ...'는'$ ("# crofthouse") .css ("width", (newHeight/2) * 1.33)'로 가야한다. 견적 배치에 유의하십시오. 또한 mutli-CSS 선택기 또는 체인을 사용하거나 변수를 사용하여 매번 jQuery (선택기 다시 강조 표시)를 다시 작성하지 않도록하십시오. 'var house = $ (# "crofthouse"); ... house.css (...)'. 그것도'$ ("main")' –