圖片是作爲div背景存在的,div的width是100%,height是根據屏幕高度計算的。用這種方法只實現了瀏覽器縮放背景寬度上保持不變,但是高度變了
background-image: url(../images/bg_1.jpg);
background-size: 100%;
background-repeat: no-repeat;
以下是設置div高度的代碼
var changeBg = (function(){
var count = 0,
height = (document.body.scrollHeight > document.documentElement.scrollHeight ? document.body.scrollHeight : document.documentElement.scrollHeight) - $(".header").outerHeight() - $(".footer").outerHeight() + 'px',
$bg = $(".home-bg");
$bg.css({
height: height
});
if(_searchConfig["catagory"]["indexBackgroundImage"] && _searchConfig["catagory"]["indexBackgroundImage"].length > 0){
setInterval(function(){
$bg.css({
background: '#425061 url("' + _searchConfig["catagory"]["indexBackgroundImage"][count].properties.imageUrl + '") repeat center',
height: height
});
count++;
if(count >= _searchConfig["catagory"]["indexBackgroundImage"].length){
count = 0;
}
}, 5000);
}
})();
先寫這麼多,有空再來改