この関数を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 ")' –