感谢https://blog.csdn.net/u013247277/article/details/70810124提供的思路,在原博代码的基础上实现了自动切换图片,并且图片大小不随网页缩放而变化
<style type="text/css">
*{margin:0;padding:0;}
.d1 {
position: absolute;
width: 100vw;
height: 100vh;
overflow: hidden;
}
.d2{
position: absolute;
width: 100%;
height: 100%;
background: no-repeat 50% 50%;/*不重复,水平居中,垂直居中*/
background-size: cover;
opacity:0;
transition:opacity 1s;
}
.d2:first-child{
position: absolute;
width: 100%;
height: 100%;
background: no-repeat 50% 50%;/*不重复,水平居中,垂直居中*/
background-size: cover;
opacity:1;
}
</style>
</head>
<body>
<div class="d1">
<div class="d2" style="background-image: url('img/1.jpg')"></div>
<div class="d2" style="background-image: url('img/2.jpg')">&