图片是作为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);
}
})();
先写这么多,有空再来改