【发布时间】:2023-03-08 03:35:01
【问题描述】:
我只使用 CSS 创建图像滑块。我几乎完成了编码,但我不知道我必须做什么才能使图像在滑动时不会不成比例地缩放。我仍然希望它们填充 div 而不是 100% 拉伸,我也不想剪切图像,因为我想(你)想办法做到这一点:)
这是我的代码的一部分:
div#transition3 {
width:480px;
height:360px;
-webkit-animation:trans2 12s;
-webkit-animation-iteration-count: infinite;
-webkit-box-sizing:border-box;
-webkit-background-origin:border-box;
background-scale:fill;
}
@-webkit-keyframes trans2 /* Safari and Chrome */
{
0% {background:url('../img/1.jpg') no-repeat top left;}
10% {background:url('../img/1.jpg') no-repeat top left;}
20% {background:url('../img/2.jpg') no-repeat top left;}
30% {background:url('../img/2.jpg') no-repeat top left;}
40% {background:url('../img/3.jpg') no-repeat top left;}
50% {background:url('../img/3.jpg') no-repeat top left;}
60% {background:url('../img/4.jpg') no-repeat top left;}
70% {background:url('../img/4.jpg') no-repeat top left;}
80% {background:url('../img/5.jpg') no-repeat top left;}
90% {background:url('../img/5.jpg') no-repeat top left;}
100% {background:url('../img/1.jpg') no-repeat top left;}
}
这是一个小提琴:http://jsfiddle.net/qDmS8/3/。 我希望你知道我的意思并能够帮助我。
提前致谢!
【问题讨论】:
-
不是
background-size:cover吗?不是background-scale:fill?我以前从未见过。 -
使用
cover代替fill: jsfiddle.net/qDmS8/4 -
你说的都是对的。它是背景大小:填充。但是现在看看它。它的行为有问题。此外,我不希望第一个图像转换为下一个图像。它应该在不变形的情况下褪色。 jsfiddle.net/qDmS8/16
-
对不起,我的意思是背景尺寸:封面!
标签: image google-chrome css slider