我有靜態的HTML結構和我的背景圖像是全屏每頁。增加了一個img標籤標籤後:更改功能元素IMG到DIV背景
<img src="img/about.jpg" id="static_bg" alt="">
和CSS:
#static_bg { position: fixed; top: 0; left: 0; z-index: -2;}
.staticbgwidth { width: 100%; }
.staticbgheight { height: 100%; }
而且最終,我的JS代碼:
$(window).load(function() {
var theWindow = $(window),
$bg = $("#static_bg"),
aspectRatio = $bg.width()/$bg.height();
function resizeBg() {
if ((theWindow.width()/theWindow.height()) < aspectRatio) {
$bg
.removeClass()
.addClass('staticbgheight');
} else {
$bg
.removeClass()
.addClass('staticbgwidth');
}
}
theWindow.resize(resizeBg).trigger("resize");
});
是啊,它的工作好。但我想要刪除我的IMG並添加DIV背景。當我改變這個時,不要使用JS。
我該如何解決?謝謝。
ü想到什麼格的背景HTML? –