gpt4 book ai didi

html - 图像无法使用 Sprite 表正确渲染

转载 作者:行者123 更新时间:2023-11-28 05:04:48 25 4
gpt4 key购买 nike

我正在尝试使用 Sprite 表来生成动画效果。我的例子如下。图像垂直滚动。我希望图像保留在一个地方并给我动画效果,而不是垂直向下滚动。我的 CSS 中缺少什么?

@total-duration: 4s;
@steps-per-row: 15;
@duration-per-item: @total-duration / @steps-per-row;

body {background: #000;}

#interactive-animation {
margin: 0 auto;
width: 128px;
height: 128px;
background: url('https://amazed.png') center center;
-webkit-animation:
play-vertical @total-duration steps(@steps-per-row) infinite,
play-horizontal @duration-per-item steps(@steps-per-row) infinite;
animation:
play-vertical @total-duration steps(@steps-per-row) infinite,
play-horizontal @duration-per-item steps(@steps-per-row) infinite;

-webkit-animation-play-state: running;
animation-play-state: running;
}

#interactive-animation:hover {
-webkit-animation-play-state: paused;
animation-play-state: paused;
}

@-webkit-keyframes play-vertical {
0% { background-position-y: 0; }
100% { background-position-y: 100%; }
//100% { background-position-y: -29px; }
}

@-webkit-keyframes play-horizontal {
0% { background-position-x: 0; }
100% { background-position-x: 100%; }
//100% { background-position-x: -1814px; }
}

最佳答案

尝试下面的代码,执行sprite动画我们需要包含CSS steps()动画函数steps()用于中断连续动画或过渡到步骤。

body{
background:black;
}
#interactive-animation {
margin: 120px auto;
width: 120px;
height: 120px;
background: url('https://samsungvr.com/ui/CMS/wow.png');
-webkit-animation: mv 2s steps(2) infinite;
overflow:hidden;
}
@-webkit-keyframes mv{
0% { background-position-y: 0; }
100% { background-position-y: 100%; }
}
<div id="interactive-animation"></div>

关于html - 图像无法使用 Sprite 表正确渲染,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39884575/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com