0
我試圖在另一層上疊加2個圖像1,並使它們使用jQuery無限滾動。我能夠使圖像在CSS中滾動和圖層,但動畫變得非常生澀。我如何使用jQuery在圖像上創建無限水平滾動並保持動畫平滑?如何在jQuery中無限水平滾動圖像?
到目前爲止我的代碼:
CSS:
@keyframes animatedBackground {
from { background-position: 0 0; }
to { background-position: 100% 0; }
}
#animate-area {
width: 100vw;
height: 100vw;
background-image: url(http://oi64.tinypic.com/2r7ri29.jpg);
background-position: 0px 0px;
background-repeat: repeat-x;
animation: animatedBackground 135s linear infinite;
}
#animate-area2 {
width: 100vw;
height: 100vw;
background-image: url(http://oi67.tinypic.com/2niy905.jpg);
background-repeat: repeat-x;
position: relative;
animation: animatedBackground 80s linear infinite;
}
和HTML:
<div id="animate-area"></div>
<div id="animate-area2"></div>
這不是問題,gaetanoM。問題在於使用'%'。這個'%'不是指背景大小,而是指元素大小。所以只有當元素與背景具有相同的寬度時纔會工作。這是一個棘手的問題要解決。如果你知道如何削減你的背景,在一定的w/h範圍內,「background-size:cover」就可以工作。 –
@AndreiGheorghiu非常感謝你的信息。這非常珍貴。再次感謝 – gaetanoM