我有以下 HTML 代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<link rel= "stylesheet" href = "style.css"></a>
<body>
<div class = "wrapper">
'<img src="compsci_coffee_blend_1.png" height = 150px width = 150px class = "coffee">
</div>
</body>
</html>
style.css 在哪里:
position: relative;
}
.coffee{
animation-name: slide; /*tells image which set of keyframes to take one */
animation-duration: 2s; /*how long animation should take */
}
/* define keyframe animation */
@keyframes slide{
from{transform: translateX(0);} /*start at 0 */
to {transform:translateX(900px);}
}
这很好用,图像在屏幕上移动。 但是,当我缩小浏览器的窗口时,图像仍会全屏移动浏览器的整个长度,因此它被截断了,您看不到它。 我怎样才能解决这个问题? (例如,我怎样才能使动画缩放到浏览器大小?)
谢谢!
最佳答案
只需使用百分比 %:
@keyframes slide{
from{transform: translateX(0);} /*start at 0 */
to {transform:translateX(80%);}
关于html - 调整浏览器大小影响动画 - CSS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58968516/