我有這方面的工作的JavaScript代碼確實對init
和resize
一些調整大小:的Javascript:代碼投入功能時,沒有得到執行
(function (w) {
w.init = function() {
var w = window.innerWidth;
var h = window.innerHeight;
//resize_font;
var fs = parseInt(w/26);
document.body.style.fontSize = fs + "px";
//resize_cover;
var logo = get_by_id("logo");
var logo_height = logo.clientHeight;
var menu = get_by_id("menu");
var menu_height = menu.clientHeight;
var cover_height = logo_height + menu_height;
var distance_top = (h - cover_height)/2.5;
var container = get_by_id("container");
container.style.paddingTop = distance_top + "px";
}
w.resize = function() {
var w = window.innerWidth;
var h = window.innerHeight;
//resize_font;
var fs = parseInt(w/26);
document.body.style.fontSize = fs + "px";
//resize_cover;
var logo = get_by_id("logo");
var logo_height = logo.clientHeight;
var menu = get_by_id("menu");
var menu_height = menu.clientHeight;
var cover_height = logo_height + menu_height;
var distance_top = (h - cover_height)/2.5;
var container = get_by_id("container");
container.style.paddingTop = distance_top + "px";
}
}
現在我想重構代碼,用於調整字體和翻唱成一個函數,但 我無法讓它工作。我試過這個:
(function (w) {
w.init = function() {
var w = window.innerWidth;
var h = window.innerHeight;
resize_font;
resize_cover;
}
w.resize = function() {
var w = window.innerWidth;
var h = window.innerHeight;
resize_font;
resize_cover;
}
function resize_cover() {
var logo = get_by_id("logo");
var logo_height = logo.clientHeight;
var menu = get_by_id("menu");
var menu_height = menu.clientHeight;
var cover_height = logo_height + menu_height;
var distance_top = (h - cover_height)/2.5;
var container = get_by_id("container");
container.style.paddingTop = distance_top + "px";
}
function resize_font() {
var fs = parseInt(w/26);
document.body.style.fontSize = fs + "px";
}
}
控制檯不顯示任何錯誤,但調整大小沒有發生。我究竟做錯了什麼?
Ehhh,究竟你認爲'resize_font;'呢? – Amit
呃,調整font_size的大小。 – Flip