html - 调整浏览器大小影响动画 - CSS

标签 html css animation browser resize

我有以下 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/

相关文章:

python - Django - 加载 css 的问题

javascript - Firefox svg 渲染 : how to get real g position?

ios - 如何对简单的 UIView 动画执行操作

javascript - 按钮背景颜色切换

javascript - 导航菜单没有正确的动画

html - 内联导航示例不起作用

Swift:UITableViewCell从右到左弹跳动画

html - CSS 动画在 Firefox 中不起作用 - 伪

javascript - 使用 jQuery 从 CSS href 中查找服务器名称

html - 如何将具有不相等的 <li> 的 <ul> 拆分为 2 行并显示 <li> 中心