我能够通过将图像加载到子 div 中来解决这个问题。
<div class='slide'>
<div class='img' style='background-image:url(img/slide1.jpg)'></div>
</div>
然后调整图像容器的比例。
#slideshow .slide {
position:absolute;
top:0%;
left:0%;
height:100%;
width:100%;
background-position:center center;
overflow:hidden;
}
#slideshow .img {
position:absolute;
background-size:cover;
top:-5%;
left:-5%;
width:110%;
height:110%;
transition: width 1s, height 1s, top 1s, left 1s;
}
#slideshow .active .img{
width:100%;
height:100%;
top:0;
left:0;
}
完整的幻灯片标记
<div id='slideshow' class='slider' >
<div class='slides'>
<div class='slide'>
<div class='img' style='background-image:url(img/slide1.jpg)'></div>
<div class='caption'>
<hr />
<h1>PRIVATE HAVEN</h1>
</div>
</div>
<div class='slide'>
<div class='img' style='background-image:url(img/slide2.jpg)'></div>
<div class='caption'>
<hr />
<h1>BLISSFUL SATISFACTION</h1>
</div>
</div>
<div class='slide' >
<div class='img' style='background-image:url(img/slide3.jpg)'></div>
<div class='caption'>
<hr />
<h1>LIVE IN NATURE AT THE MOUNTAIN’S DOOR</h1>
</div>
</div>
</div>
</div>