用css和js解决背景图片切换和渐变效果
1.css部分
.b{background-image:url(/image/dayin.gif)left top no-repeat;
width: 100%; min-width:1200px; height: 100%; position: absolute; top: 0; left: 0;
background-size: cover;
-webkit-transition: all 1s linear; transition: all 1s linear;
}
搭好css用标签中class实现, all 1s linear 实现几秒渐变
2.js部分
function goo(n){
var num = Number(n);
if(num%3==1){
setTimeout(function(){
document.getElementById('mainCnt').style.backgroundImage='url(${pageContext.request.contextPath }/images/shop1.jpg)';
goo(num+1);
}
,6000);
}else if(num%3==2){
setTimeout(function(){
document.getElementById('mainCnt').style.backgroundImage='url(${pageContext.request.contextPath }/images/shop2.jpg)';
goo(num+1);
}
,6000);
}else{
setTimeout(function(){
document.getElementById('mainCnt').style.backgroundImage='url(${pageContext.request.contextPath }/images/shop.jpg)';
goo(num+1);
}
,6000);
}
}
goo(1);
编写js加载页面的时候就执行
3.标签编写
<body class="b" id="doo">
</body>
4.总结
基本用于登陆界面的多个背景变换,让多个图片在页面上渐变显示